forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_test.go
135 lines (115 loc) · 2.66 KB
/
team_test.go
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"strings"
"testing"
)
func TestTeamJson(t *testing.T) {
o := Team{Id: NewId(), DisplayName: NewId()}
json := o.ToJson()
ro := TeamFromJson(strings.NewReader(json))
if o.Id != ro.Id {
t.Fatal("Ids do not match")
}
}
func TestTeamIsValid(t *testing.T) {
o := Team{}
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.Id = NewId()
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.CreateAt = GetMillis()
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.UpdateAt = GetMillis()
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.Email = strings.Repeat("01234567890", 20)
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.Email = "[email protected]"
o.DisplayName = strings.Repeat("01234567890", 20)
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.DisplayName = "1234"
o.Name = "ZZZZZZZ"
if err := o.IsValid(true); err == nil {
t.Fatal("should be invalid")
}
o.Name = "zzzzz"
o.Type = TEAM_OPEN
if err := o.IsValid(true); err != nil {
t.Fatal(err)
}
}
func TestTeamPreSave(t *testing.T) {
o := Team{DisplayName: "test"}
o.PreSave()
o.Etag()
}
func TestTeamPreUpdate(t *testing.T) {
o := Team{DisplayName: "test"}
o.PreUpdate()
}
var domains = []struct {
value string
expected bool
}{
{"spin-punch", true},
{"-spin-punch", false},
{"spin-punch-", false},
{"spin_punch", false},
{"a", false},
{"aa", false},
{"aaa", false},
{"aaa-999b", true},
{"b00b", true},
{"b))b", false},
{"test", true},
}
func TestValidTeamName(t *testing.T) {
for _, v := range domains {
if IsValidTeamName(v.value) != v.expected {
t.Errorf("expect %v as %v", v.value, v.expected)
}
}
}
var tReservedDomains = []struct {
value string
expected bool
}{
{"test-hello", true},
{"test", true},
{"admin", true},
{"Admin-punch", true},
{"spin-punch-admin", false},
}
func TestReservedTeamName(t *testing.T) {
for _, v := range tReservedDomains {
if IsReservedTeamName(v.value) != v.expected {
t.Errorf("expect %v as %v", v.value, v.expected)
}
}
}
func TestCleanTeamName(t *testing.T) {
if CleanTeamName("Jimbo's Team") != "jimbos-team" {
t.Fatal("didn't clean name properly")
}
if len(CleanTeamName("Test")) != 26 {
t.Fatal("didn't clean name properly")
}
if CleanTeamName("Team Really cool") != "really-cool" {
t.Fatal("didn't clean name properly")
}
if CleanTeamName("super-duper-guys") != "super-duper-guys" {
t.Fatal("didn't clean name properly")
}
}