-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathchecklist_test.go
150 lines (123 loc) · 4 KB
/
checklist_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
package trello
import (
"testing"
)
func TestCreateChecklist(t *testing.T) {
c := testClient()
c.BaseURL = mockResponse("checklists", "checklist-create.json").URL
card := Card{
Name: "Test Card Create",
IDList: "57f03a06b5ff33a63c8be316",
ID: "5c41028905a859019e323bc9",
IDBoard: "5c41027ca9c378795b5a5036",
}
checklistName := "hello"
cl, err := c.CreateChecklist(&card, checklistName, Arguments{"pos": "33"})
if err != nil {
t.Error(err)
}
if card.Checklists[0].ID != "5cc064cb72fbdb774ff22bac" {
t.Errorf("Expected checklist to pick up an ID. Instead got '%s'.", card.ID)
}
if cl.ID != "5cc064cb72fbdb774ff22bac" {
t.Errorf("Expected checklist to pick up an ID. Instead got '%s'.", cl.ID)
}
if cl.IDCard != card.ID {
t.Errorf("Expected checklist to pick up card ID. Instead got '%s'.", cl.IDCard)
}
if cl.IDBoard != card.IDBoard {
t.Errorf("Expected checklist to pick up board ID. Instead got '%s'.", cl.IDBoard)
}
if card.IDBoard != "5c41027ca9c378795b5a5036" {
t.Errorf("Expected card to keep its IDBOard. Instead got '%s'.", card.IDBoard)
}
if cl.Name != checklistName {
t.Errorf("Expected checklist name to be set. Instead got '%s'.", cl.Name)
}
if cl.client == nil {
t.Errorf("Expected checklist to pick up a client. Instead got nil.")
}
if cl.Pos != 33 {
t.Errorf("Expected the returned checklist to pick up a position. Instead got '%v'.", cl.Pos)
}
}
func TestCreateCheckItem(t *testing.T) {
c := testClient()
c.BaseURL = mockResponse("checklists", "checkitem-create.json").URL
cl := Checklist{
Name: "SomeName",
ID: "5cc05fc2a44eed7872662d1b",
client: c,
}
checkItemName := "hello2"
item, err := cl.CreateCheckItem(checkItemName, Arguments{"pos": "35", "checked": "true"})
if err != nil {
t.Error(err)
}
if item.IDChecklist != "5cc05fc2a44eed7872662d1b" {
t.Errorf("Expected checkitem to pick up checklist ID. Instead got '%s'.", item.IDChecklist)
}
if item.ID != "5cc05fddf0d64d1c89e2a3b5" {
t.Errorf("Expected checkitem to pick up an ID. Instead got '%s'.", item.ID)
}
if len(cl.CheckItems) != 1 {
t.Errorf("Expected checklist to pick up the created checkitem. Instead got '%v'.", len(cl.CheckItems))
}
if cl.CheckItems[0] != *item {
t.Errorf("Expected the returned item and the checkitem inside the checklist to be equal.\n got: %#v\nwant: %#v", cl.CheckItems[0], *item)
}
if item.Pos != 35 {
t.Errorf("Expected the returned item to pick up a position. Instead got '%v'.", item.Pos)
}
if item.State != "complete" {
t.Errorf("Expected checked to be set. Instead got '%s'.", item.State)
}
}
func TestGetChecklist(t *testing.T) {
checklist := testChecklist(t)
if checklist.Name != "Example checklist" {
t.Errorf("Name incorrect. Got '%s'", checklist.Name)
}
if checklist.Pos != 1 {
t.Errorf("Pos incorrect. Got '%0.2f'", checklist.Pos)
}
if len(checklist.CheckItems) != 1 {
t.Errorf("len(checklist.CheckItems) incorrect. Got '%0.2f'", checklist.Pos)
}
if checklist.CheckItems[0].Name != "Example checkItem" {
t.Errorf("CheckItem Name incorrect. Got '%s'", checklist.CheckItems[0].Name)
}
if checklist.CheckItems[0].State != "complete" {
t.Errorf("CheckItem State incorrect. Got '%s'", checklist.CheckItems[0].State)
}
if checklist.CheckItems[0].Pos != 2 {
t.Errorf("CheckItem Pos incorrect. Got '%0.2f'", checklist.CheckItems[0].Pos)
}
}
func TestChecklistSetClient(t *testing.T) {
cl := Checklist{}
client := testClient()
cl.SetClient(client)
if cl.client == nil {
t.Error("Expected non-nil CheckList.client")
}
}
func TestCheckItemSetClient(t *testing.T) {
ci := CheckItem{}
client := testClient()
ci.SetClient(client)
if ci.client == nil {
t.Error("Expected non-nil CheckItem.client")
}
}
// Utility function to get a simple response from Client.GetChecklist()
//
func testChecklist(t *testing.T) *Checklist {
c := testClient()
c.BaseURL = mockResponse("checklists", "checklist-api-example.json").URL
checklist, err := c.GetChecklist("4eea503", Defaults())
if err != nil {
t.Fatal(err)
}
return checklist
}