summaryrefslogtreecommitdiffstats
path: root/model/reaction_test.go
blob: e980b106d098f40ccb7f9cd1a197a1647a7170d3 (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
// 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 = ""
	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")
	}
}