-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.e2e.test.ts
358 lines (313 loc) · 8.77 KB
/
app.e2e.test.ts
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import test from 'tape'
import utils from './test/utils'
const { api, interceptors } = utils
import kudoModel from './models/kudos'
import ObjectId from 'bson-objectid'
test('before', async function (t) {
t.plan(1)
await utils.dbSetup()
t.ok(1)
})
// help
test('should return 200 for help command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=help&team_id=mypasel')
.expect(200)
.then(t.ok)
})
test('should return right response for help command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=help&team_id=mypasel')
.expect({
response_type: 'in_channel',
text: `
Want to congratulate a team member? Do \`\kudo add @teammember <text>\`
Want to list a number of recent kudos? Do \`\kudo list <number>\`. use \`*\` in place of \`<number>\` to list all
Want to update a kudo? Do \`\kudo replace <kudoId> <text>\`
Want to get ranked members in terms of kudos? Do \`\kudo top <number>\` use \`*\` in place of \`<number>\` to get all ranks
Want to delete a kudo? Do \`\kudo delete <kudoId>\`
`
})
.then(t.ok)
})
// list
test('should return 200 for list command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=list&team_id=mypasel')
.expect(200)
.then(t.ok)
})
test('should return right response for list command when no kudos', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=list&team_id=mypasel')
.expect({
response_type: 'in_channel',
text: 'There are currently no kudos'
})
.then(t.ok)
})
test('should return right response for list command when number is passed and kudos exist', async (t) => {
t.plan(1)
const kudo = await kudoModel().create({
text: 'nice one',
recipient: '123a',
platform: 'slack',
workspace: '123b'
})
return api()
.post('/kudos/slack')
.send('text=list 1&team_id=mypasel')
.expect({
response_type: 'in_channel',
text: `*Current List of Kudos*\n[${kudo._id}] ${kudo.text} (recipient: <@${kudo.recipient}>)`
})
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
// top
test('should return 200 for top command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=top&team_id=mypasel')
.expect(200)
.then(t.ok)
})
test('should return right response for top command when no kudos', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=top&team_id=mypasel')
.expect({
response_type: 'in_channel',
text: 'There are currently no kudos'
})
.then(t.ok)
})
test('should return right response for top command if there are kudos', async (t) => {
t.plan(1)
const firstRecipient = 'mank'
await Promise.all([...Array(2)].map(() => kudoModel().create({
text: 'good product',
recipient: firstRecipient,
platform: 'slack',
workspace: '343a'
})))
const secondRecipient = 'oswell'
await kudoModel().create({
text: 'wonderful customer service',
recipient: secondRecipient,
platform: 'slack',
workspace: '343a'
})
return api()
.post('/kudos/slack')
.send('text=top *&team_id=mypasel')
.expect({
response_type: 'in_channel',
text: `*Kudos Leaderboard*\n<@${firstRecipient}> : 2\n<@${secondRecipient}> : 1`
})
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
// user
test('should return 200 for user command', (t) => {
t.plan(1)
interceptors.mockGetSlackUsers({
members: [
{
id: '123',
name: 'clarke'
}
]
})
return api()
.post('/kudos/slack')
.send('text=user @clarke&team_id=mypasel')
.expect(200)
.then(t.ok)
})
test('should return right response if user has no existing kudos', async (t) => {
t.plan(1)
const userId = '1234'
const username = 'clarke'
interceptors.mockGetSlackUsers({
members: [
{
id: userId,
name: username
}
]
})
return api()
.post('/kudos/slack')
.send(`text=user @${username}&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: `<@${userId}> currently has no kudos`
})
.then(t.ok)
})
test('should return right response if there are kudos', async (t) => {
t.plan(1)
const recipient = 'mank'
const userId = '1234'
interceptors.mockGetSlackUsers({
members: [
{
id: userId,
name: recipient
}
]
})
const savedKudos = await Promise.all([...Array(2)].map(async () => {
return kudoModel().create({
text: 'good product',
recipient: userId,
platform: 'slack',
workspace: '343a'
})
}))
return api()
.post('/kudos/slack')
.send(`text=user @${recipient}&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: `<@${userId}>'s *Kudos*\n${savedKudos.map(kudo => `[${kudo._id}] ${kudo.text}`).join('\n')}`
})
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
// delete
test('should return 200 for delete command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send('text=delete&team_id=mypasel')
.expect(200)
.then(t.ok)
})
test('should return right response for delete kudo command', async (t) => {
t.plan(1)
const result = await kudoModel().create({
text: 'nice one',
recipient: '123a',
platform: 'slack',
workspace: '123b'
})
return api()
.post('/kudos/slack')
.send(`text=delete ${result._id}&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: 'Kudo successfully rescinded.'
})
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
// replace
test('should return 200 for replace command', (t) => {
t.plan(1)
return api()
.post('/kudos/slack')
.send(`text=replace ${new ObjectId().toHexString()} nice work Clarke!&team_id=mypasel`)
.expect(200)
.then(t.ok)
})
test('should return right response for replace command for existing kudo', async (t) => {
t.plan(1)
const kudo = await kudoModel().create({
text: 'nice one',
recipient: '123a',
platform: 'slack',
workspace: '123b'
})
return api()
.post('/kudos/slack')
.send(`text=replace ${kudo._id} nice work Clarke!&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: `Kudo with id ${kudo._id} successfully updated`
})
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
test('should return right response for replace command for non-existing kudo', async (t) => {
t.plan(1)
const sampleId = new ObjectId().toHexString()
return api()
.post('/kudos/slack')
.send(`text=replace ${sampleId} nice work Clarke!&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: `Kudo with id ${sampleId} not found`
})
.then(t.ok)
})
// add
test('should return 200 for add command', (t) => {
t.plan(1)
const userId = '1234'
const username = 'clarke'
interceptors.mockGetSlackUsers({
members: [
{
id: userId,
name: username
}
]
})
return api()
.post('/kudos/slack')
.send(`text=add @${username} nice work Clarke!&team_id=mypasel`)
.expect(200)
.then(async () => {
t.ok(1)
await utils.tearDown()
})
})
test('should return right response for add command', (t) => {
t.plan(1)
const userId = '1234'
const username = 'clarke'
interceptors.mockGetSlackUsers({
members: [
{
id: userId,
name: username
}
]
})
return api()
.post('/kudos/slack')
.send(`text=add @${username} nice work Clarke!&team_id=mypasel`)
.expect({
response_type: 'in_channel',
text: `<@${userId}> just received a kudo from you!`
}
)
.then(t.ok)
})
test('after', async function (t) {
t.plan(1)
await utils.tearDown(true)
t.ok(1)
})