forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action-collection_test.go
82 lines (72 loc) · 2.83 KB
/
action-collection_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
package trello
import (
"testing"
)
func TestContainsCardCreation(t *testing.T) {
ac := make(ActionCollection, 4)
ac[0] = &Action{Type: "commentCard"}
ac[1] = &Action{Type: "updateCard"}
ac[2] = &Action{Type: "convertToCardFromCheckItem"}
ac[3] = &Action{Type: "createBoard"}
if !ac.ContainsCardCreation() {
t.Errorf("This ActionCollection contains a card creation action, but the method returned false.")
}
}
func TestFilterToCardCreationActions(t *testing.T) {
ac := make(ActionCollection, 6)
ac[0] = &Action{Type: "commentCard"}
ac[1] = &Action{Type: "createCard"}
ac[2] = &Action{Type: "createBoard"}
ac[3] = &Action{Type: "emailCard"}
ac[4] = &Action{Type: "copyCard"}
ac[5] = &Action{Type: "convertToCardFromCheckItem"}
ccs := ac.FilterToCardCreationActions()
if len(ccs) != 4 {
t.Errorf("Expected 4 cards, got %d", len(ccs))
}
if ccs[0].Type != "createCard" {
t.Error("Order was not preserved.")
}
}
func TestFilterToListChangeActions(t *testing.T) {
ac := make(ActionCollection, 5)
ac[0] = &Action{Type: "updateCard"} // An update that didn't change the list
ac[1] = &Action{Type: "updateCard", Data: &ActionData{ListAfter: &List{ID: "testID", Name: "List 2"}}}
ac[2] = &Action{Type: "updateCard", Data: &ActionData{Card: &ActionDataCard{Closed: true}}} // Card was archived
ac[3] = &Action{Type: "updateCard", Data: &ActionData{Old: &ActionDataCard{Closed: true}}} // Card was unarchived
ac[4] = &Action{Type: "commentCard"}
lcas := ac.FilterToListChangeActions()
if len(lcas) != 3 {
t.Errorf("Expected 3, got %d", len(lcas))
}
}
func TestFilterToCardMembershipChangeActions(t *testing.T) {
ac := make(ActionCollection, 5)
ac[0] = &Action{Type: "addMemberToCard"}
ac[1] = &Action{Type: "removeMemberFromCard"}
ac[2] = &Action{Type: "updateCard", Data: &ActionData{Old: &ActionDataCard{Closed: true}}}
ac[3] = &Action{Type: "updateCard", Data: &ActionData{Card: &ActionDataCard{Closed: true}}}
ac[4] = &Action{Type: "commentCard"}
mcas := ac.FilterToCardMembershipChangeActions()
if len(mcas) != 4 {
t.Errorf("Expected 1, got %d", len(mcas))
}
}
func TestGetLastCommentAction(t *testing.T) {
expectedText := "rightComment"
ac := make(ActionCollection, 9)
ac[0] = &Action{Type: "addMemberToCard"}
ac[1] = &Action{Type: "commentCard", Data: &ActionData{Text: expectedText}}
ac[2] = &Action{Type: "updateCard"}
ac[3] = &Action{Type: "updateCard"}
ac[4] = &Action{Type: "commentCard", Data: &ActionData{Text: "wrongText1"}}
ac[5] = &Action{Type: "removeMemberFromCard"}
ac[6] = &Action{Type: "removeMemberFromCard"}
ac[7] = &Action{Type: "commentCard", Data: &ActionData{Text: "wrongText2"}}
ac[8] = &Action{Type: "updateCard"}
lastCommentAction := ac.LastCommentAction()
resultText := lastCommentAction.Data.Text
if resultText != expectedText {
t.Errorf("Expected comment text %v, got %v", expectedText, resultText)
}
}