summaryrefslogtreecommitdiffstats
path: root/model/reaction_test.go
blob: a35750477572bcc6ec4e9d1ee85dcb5db0703af7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Copyright (c) 2016-present 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 = strings.Repeat("a", 64)
	if err := reaction.IsValid(); err != nil {
		t.Fatal(err)
	}

	reaction.EmojiName = "emoji-"
	if err := reaction.IsValid(); err != nil {
		t.Fatal(err)
	}

	reaction.EmojiName = "emoji_"
	if err := reaction.IsValid(); err != nil {
		t.Fatal(err)
	}

	reaction.EmojiName = "+1"
	if err := reaction.IsValid(); err != nil {
		t.Fatal(err)
	}

	reaction.EmojiName = "emoji:"
	if err := reaction.IsValid(); err == nil {
		t.Fatal(err)
	}

	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.CreateAt = 0
	if err := reaction.IsValid(); err == nil {
		t.Fatal("create at should be invalid")
	}
}