-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathaction_test.go
153 lines (141 loc) · 3.24 KB
/
action_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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
import (
"testing"
)
func TestGetActionsOnBoard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("actions", "board-actions-api-example.json").URL
actions, err := board.GetActions(Defaults())
if err != nil {
t.Fatal(err)
}
if len(actions) != 4 {
t.Errorf("Expected 4 actions, got %d", len(actions))
}
}
func TestGetActionsOnList(t *testing.T) {
list := testList(t)
list.client.BaseURL = mockResponse("actions", "list-actions-api-example.json").URL
actions, err := list.GetActions(Defaults())
if err != nil {
t.Fatal(err)
}
if len(actions) != 2 {
t.Errorf("Expected 2 actions, got %d", len(actions))
}
}
func TestGetActionsOnCard(t *testing.T) {
card := testCard(t)
card.client.BaseURL = mockResponse("actions", "card-actions-api-example.json").URL
actions, err := card.GetActions(Defaults())
if err != nil {
t.Fatal(err)
}
if len(actions) != 50 {
t.Errorf("Expected 50 actions, got %d", len(actions))
}
}
func TestListAfterActionOnUpdateCard(t *testing.T) {
a := &Action{
Type: "updateCard",
Data: &ActionData{
ListBefore: &List{Name: "Before"},
ListAfter: &List{Name: "After"},
},
}
l := ListAfterAction(a)
if l.Name != "After" {
t.Errorf("Incorrect List name '%s'", l.Name)
}
}
func TestListAfterActionOnArchive(t *testing.T) {
a := &Action{
Type: "updateCard",
Data: &ActionData{
List: &List{Name: "SameList"},
Board: &Board{},
Card: &ActionDataCard{Closed: true},
Old: &ActionDataCard{Closed: false},
},
}
l := ListAfterAction(a)
if l != nil {
t.Error("ListAfterAction() should be nil after an archive.")
}
}
func TestListAfterActionOnUnarchive(t *testing.T) {
a := &Action{
Type: "updateCard",
Data: &ActionData{
List: &List{Name: "SameList"},
Board: &Board{},
Card: &ActionDataCard{Closed: false},
Old: &ActionDataCard{Closed: true},
},
}
l := ListAfterAction(a)
if l == nil {
t.Error("ListAfterAction() should not be nil after an unarchive.")
}
if l.Name != "SameList" {
t.Errorf("Incorrect List name '%s'.", l.Name)
}
}
func TestListAfterActionOnCopyCard(t *testing.T) {
a := &Action{
Type: "copyCard",
Data: &ActionData{
List: &List{Name: "FirstList"},
Board: &Board{},
Card: &ActionDataCard{Closed: false},
},
}
l := ListAfterAction(a)
if l == nil {
t.Error("ListAfterAction() should not be nil after a copy")
}
if l.Name != "FirstList" {
t.Errorf("Incorrect List name '%s'.", l.Name)
}
}
func TestActionDidCommentCard(t *testing.T) {
tests := []struct {
name string
fields *Action
want bool
}{
{
name: "positive",
fields: &Action{
Type: "commentCard",
},
want: true,
},
{
name: "negative",
fields: &Action{
Type: "updateCard",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.fields.DidCommentCard(); got != tt.want {
t.Errorf("Action.DidCommentCard() = %v, want %v", got, tt.want)
}
})
}
}
func TestActionSetClient(t *testing.T) {
a := Action{}
client := testClient()
a.SetClient(client)
if a.client == nil {
t.Error("Expected non-nil Action.client")
}
}