-
Notifications
You must be signed in to change notification settings - Fork 1
/
wekanTaskforce_integration_test.go
362 lines (308 loc) · 11.4 KB
/
wekanTaskforce_integration_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
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
359
360
361
362
//go:build integration
// +build integration
// nolint:errcheck
package main
import (
"testing"
"github.com/signaux-faibles/libwekan"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func createBoard(t *testing.T, wekan libwekan.Wekan, suffix string) (libwekan.Board, libwekan.Swimlane, libwekan.List) {
board := libwekan.BuildBoard(t.Name()+"_Title"+suffix, t.Name()+"_Slug"+suffix, "board")
wekan.InsertBoard(ctx, board)
swimlane := libwekan.BuildSwimlane(board.ID, "swimlane", t.Name()+"_Swimlane"+suffix, 0)
wekan.InsertSwimlane(ctx, swimlane)
list := libwekan.BuildList(board.ID, t.Name()+"_List"+suffix, 0)
wekan.InsertList(ctx, list)
return board, swimlane, list
}
func createUser(
t *testing.T,
wekan libwekan.Wekan,
suffix string,
board *libwekan.Board,
card *libwekan.Card,
) libwekan.User {
name := t.Name() + suffix
user := libwekan.BuildUser(name, name, name)
err := wekan.InsertUser(ctx, user)
require.NoError(t, err)
if board != nil {
boardMember := libwekan.BoardMember{
UserID: user.ID,
IsActive: true,
}
err = wekan.AddMemberToBoard(ctx, board.ID, boardMember)
require.NoError(t, err)
}
if card != nil {
err := wekan.AddSelfMemberToCard(ctx, *card, user)
require.NoError(t, err)
}
return user
}
func createCard(
t *testing.T,
wekan libwekan.Wekan,
suffix string,
boardID libwekan.BoardID,
swimlaneID libwekan.SwimlaneID,
listID libwekan.ListID,
) libwekan.Card {
name := t.Name() + suffix
card := libwekan.BuildCard(boardID, listID, swimlaneID, name, "desc : "+name, wekan.AdminID())
wekan.InsertCard(ctx, card)
return card
}
func createLabel(t *testing.T, wekan libwekan.Wekan, suffix string, boardID libwekan.BoardID, cardID *libwekan.CardID) libwekan.BoardLabel {
boardLabel := libwekan.NewBoardLabel(t.Name()+"_Label"+suffix, "red")
board, _ := boardID.GetDocument(ctx, &wekan)
wekan.InsertBoardLabel(ctx, board, boardLabel)
if cardID != nil {
card, _ := cardID.GetDocument(ctx, &wekan)
wekan.AddLabelToCard(ctx, card.ID, boardLabel.ID)
}
return boardLabel
}
func TestWekanTaskforce_AddMissingRules_whenEverythingFine(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err := pipeline.StopAfter(wekan, users, stageAddMissingRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.Contains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.NoError(err)
require.Len(t, rules, 2)
actualRule := rules[0]
ass.Equal(string(userOnBoard.Username), string(actualRule.Action.Username))
ass.Equal(label.ID, actualRule.Trigger.LabelID)
}
func TestWekanTaskforce_AddMissingRules_whenScopeNotWekan(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{""},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err := pipeline.StopAfter(wekan, users.selectScopeWekan(), stageAddMissingRulesAndCardMembership)
require.NoError(t, err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_AddMissingRules_WhenInactiveMember(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err := pipeline.StopAfter(wekan, users, stageAddMissingRulesAndCardMembership)
ass.NoError(err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_AddMissingRules_WhenNotMember(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", nil, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err := pipeline.StopAfter(wekan, users, stageAddMissingRulesAndCardMembership)
ass.NoError(err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_AddMissingRules_whenBoardHasNotLabel(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", nil, nil)
// label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{},
taskforces: []string{"fakeLabel"},
},
}
// WHEN
err := pipeline.StopAfter(wekan, users, stageAddMissingRulesAndCardMembership)
ass.NoError(err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_RemoveExtraRules_whenUserLosesTaskforce(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
initialUsers := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
err := pipeline.StopAfter(wekan, initialUsers, stageAddMissingRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{},
},
}
// WHEN
err = pipeline.StopAfter(wekan, users, stageRemoveExtraRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_RemoveExtraRules_whenUserLosesBoard(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "TestWekanTaskforce_RemoveExtraRules_whenUserLosesBoard_Slugboard")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
initialUsers := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
err := pipeline.StopAfter(wekan, initialUsers, stageAddMissingRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err = pipeline.StopAfter(wekan, users, stageRemoveExtraRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}
func TestWekanTaskforce_RemoveExtraRules_whenUserLosesWekanScope(t *testing.T) {
// GIVEN
wekan := restoreMongoDumpInDatabase(mongodb, "", t, "")
ass := assert.New(t)
board, swimlane, list := createBoard(t, wekan, "board")
cardOnBoard := createCard(t, wekan, "card", board.ID, swimlane.ID, list.ID)
userOnBoard := createUser(t, wekan, "user", &board, nil)
label := createLabel(t, wekan, "label", board.ID, &cardOnBoard.ID)
initialUsers := Users{
Username(userOnBoard.Username): User{
scope: []string{"wekan"},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
err := pipeline.StopAfter(wekan, initialUsers, stageAddMissingRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
users := Users{
Username(userOnBoard.Username): User{
scope: []string{},
email: Username(userOnBoard.Username),
boards: []string{string(board.Slug)},
taskforces: []string{string(label.Name)},
},
}
// WHEN
err = pipeline.StopAfter(wekan, users.selectScopeWekan(), stageRemoveExtraRulesAndCardMembership)
printErrChain(err, 0)
require.NoError(t, err)
// THEN
actualCard, _ := cardOnBoard.ID.GetDocument(ctx, &wekan)
ass.NotContains(actualCard.Members, userOnBoard.ID)
rules, err := wekan.SelectRulesFromBoardID(ctx, board.ID)
ass.Len(rules, 0)
}