-
Notifications
You must be signed in to change notification settings - Fork 164
/
recipient_test.go
149 lines (118 loc) · 3.95 KB
/
recipient_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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package workwx
import (
"fmt"
"testing"
c "github.com/smartystreets/goconvey/convey"
)
func TestRecipientValidation(t *testing.T) {
manyStringsFactory := func(n int) []string {
result := make([]string, n)
for i := 0; i < n; i++ {
result[i] = fmt.Sprintf("x%d", i)
}
return result
}
c.Convey("Recipient 校验逻辑", t, func() {
a := Recipient{}
c.Reset(func() {
a = Recipient{}
})
c.Convey("正向用例", func() {
c.Convey("发给单个用户", func() {
a.UserIDs = []string{"foo"}
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 1000 个用户", func() {
a.UserIDs = manyStringsFactory(1000)
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给单个部门", func() {
a.PartyIDs = []string{"foo"}
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 100 个部门", func() {
a.PartyIDs = manyStringsFactory(100)
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给单个标签", func() {
a.TagIDs = []string{"foo"}
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 100 个标签", func() {
a.TagIDs = manyStringsFactory(100)
c.Convey("应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 chatid", func() {
a.ChatID = "foo"
c.Convey("应该只通过 isValidForAppchatSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeTrue)
})
})
// TODO: 这个不知道行不行,要线上验证一下,现在是放行的
c.Convey("发给单个用户和单个部门", func() {
a.UserIDs = []string{"foo"}
a.PartyIDs = []string{"bar"}
c.Convey("目前应该只通过 isValidForMessageSend 校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeTrue)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
})
c.Convey("反向用例", func() {
c.Convey("空 Recipient", func() {
c.Convey("不应该通过校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 chatid 和单个用户", func() {
a.UserIDs = []string{"foo"}
a.ChatID = "bar"
c.Convey("不应该通过校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 1001 个用户", func() {
a.UserIDs = manyStringsFactory(1001)
c.Convey("不应该通过校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 101 个部门", func() {
a.PartyIDs = manyStringsFactory(101)
c.Convey("不应该通过校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
c.Convey("发给 101 个标签", func() {
a.TagIDs = manyStringsFactory(101)
c.Convey("不应该通过校验", func() {
c.So(a.isValidForMessageSend(), c.ShouldBeFalse)
c.So(a.isValidForAppchatSend(), c.ShouldBeFalse)
})
})
})
})
}