summaryrefslogtreecommitdiffstats
path: root/model/reaction_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'model/reaction_test.go')
-rw-r--r--model/reaction_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/model/reaction_test.go b/model/reaction_test.go
new file mode 100644
index 000000000..da73f477a
--- /dev/null
+++ b/model/reaction_test.go
@@ -0,0 +1,64 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestReactionIsValid(t *testing.T) {
+ reaction := Reaction{
+ UserId: NewId(),
+ PostId: NewId(),
+ EmojiName: "emoji",
+ CreateAt: GetMillis(),
+ }
+
+ if err := reaction.IsValid(); err != nil {
+ t.Fatal(err)
+ }
+
+ reaction.UserId = ""
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("user id should be invalid")
+ }
+
+ reaction.UserId = "1234garbage"
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("user id should be invalid")
+ }
+
+ reaction.UserId = NewId()
+ reaction.PostId = ""
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("post id should be invalid")
+ }
+
+ reaction.PostId = "1234garbage"
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("post id should be invalid")
+ }
+
+ reaction.PostId = NewId()
+ reaction.EmojiName = ""
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("emoji name should be invalid")
+ }
+
+ reaction.EmojiName = strings.Repeat("a", 65)
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("emoji name should be invalid")
+ }
+
+ reaction.EmojiName = strings.Repeat("a", 64)
+ if err := reaction.IsValid(); err != nil {
+ t.Fatal(err)
+ }
+
+ reaction.CreateAt = 0
+ if err := reaction.IsValid(); err == nil {
+ t.Fatal("create at should be invalid")
+ }
+}