This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard_test.go
207 lines (176 loc) · 4.99 KB
/
card_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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT licese.
// Details in the LICENSE file.
package trello
import (
"testing"
"time"
)
func TestCardCreatedAt(t *testing.T) {
c := Card{}
c.ID = "4d5ea62fd76aa1136000000c"
ts := c.CreatedAt()
if ts.IsZero() {
t.Error("Time shouldn't be zero.")
}
if ts.Unix() != 1298048559 {
t.Errorf("Incorrect CreatedAt() time: '%s'.", ts.Format(time.RFC3339))
}
}
func TestGetCardsOnBoard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockDynamicPathResponse().URL
cards, err := board.GetCards(Defaults())
if err != nil {
t.Fatal(err)
}
if len(cards) != 5 {
t.Errorf("Expected 5 cards, got %d", len(cards))
}
}
func TestGetCardsInList(t *testing.T) {
list := testList(t)
list.client.BaseURL = mockResponse("cards", "list-cards-api-example.json").URL
cards, err := list.GetCards(Defaults())
if err != nil {
t.Fatal(err)
}
if len(cards) != 1 {
t.Errorf("Expected 1 cards, got %d", len(cards))
}
}
func TestBoardContainsCopyOfCard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("actions", "board-actions-copyCard.json").URL
firstResult, err := board.ContainsCopyOfCard("57f50c552b96e3fffe588aad", Defaults())
if err != nil {
t.Error(err)
}
if firstResult {
t.Errorf("Incorrect Copy test: Card 57f50c552b96e3fffe588aad was never copied.")
}
secondResult, err := board.ContainsCopyOfCard("57914873fd2de1a10f3cb422", Defaults())
if err != nil {
t.Error(err)
}
if !secondResult {
t.Errorf("ContainsCopyOfCard(57f50c552b96e3fffe588aad) should have been true.")
}
}
func TestCreateCard(t *testing.T) {
c := testClient()
c.BaseURL = mockResponse("cards", "card-create.json").URL
dueDate := time.Now().AddDate(0, 0, 3)
card := Card{
Name: "Test Card Create",
Desc: "What its about",
Due: &dueDate,
IDList: "57f03a06b5ff33a63c8be316",
IDLabels: []string{"label1", "label2"},
}
err := c.CreateCard(&card, Arguments{"pos": "top"})
if err != nil {
t.Error(err)
}
if card.Pos != 8192 {
t.Errorf("Expected card to pick up a new Pos value. Instead got %.2f.", card.Pos)
}
if card.DateLastActivity == nil {
t.Error("Expected card to pick up a last activity date. Was nil.")
}
if card.ID != "57f5183c691585658d408681" {
t.Errorf("Expected card to pick up an ID. Instead got '%s'.", card.ID)
}
if len(card.Labels) < 2 {
t.Errorf("Expected card to be assigned two labels. Instead got '%v'.", card.Labels)
}
}
func TestAddCardToList(t *testing.T) {
l := testList(t)
l.client.BaseURL = mockResponse("cards", "card-posted-to-bottom-of-list.json").URL
dueDate := time.Now().AddDate(0, 0, 1)
card := Card{
Name: "Test Card POSTed to List",
Desc: "This is its description.",
Due: &dueDate,
IDLabels: []string{"label1", "label2"},
}
err := l.AddCard(&card, Arguments{"pos": "bottom"})
if err != nil {
t.Error(err)
}
if card.Pos != 32768 {
t.Errorf("Expected card to pick up a new Pos value. Instead got %.2f.", card.Pos)
}
if card.DateLastActivity == nil {
t.Error("Expected card to pick up a last activity date. Was nil.")
}
if card.ID != "57f5118667db8839dab68698" {
t.Errorf("Expected card to pick up an ID. Instead got '%s'.", card.ID)
}
if len(card.Labels) < 2 {
t.Errorf("Expected card to be assigned two labels. Instead got '%v'.", card.Labels)
}
}
func TestCopyCardToList(t *testing.T) {
c := testCard(t)
c.client.BaseURL = mockResponse("cards", "card-copied.json").URL
newCard, err := c.CopyToList("57f03a022cd45c863ca581f1", Defaults())
if err != nil {
t.Error(err)
}
if newCard.ID == c.ID {
t.Errorf("New card should have a new ID: '%s'.", newCard.ID)
}
if newCard.Pos != 16384 {
t.Errorf("Expected new card to have correct Pos value. Got %.2f", newCard.Pos)
}
}
func TestGetParentCard(t *testing.T) {
c := testCard(t)
c.client.BaseURL = mockDynamicPathResponse().URL
parent, err := c.GetParentCard(Defaults())
if err != nil {
t.Error(err)
}
if parent == nil {
t.Errorf("Problem")
}
}
func TestGetAncestorCards(t *testing.T) {
c := testCard(t)
c.client.BaseURL = mockDynamicPathResponse().URL
ancestors, err := c.GetAncestorCards(Defaults())
if err != nil {
t.Error(err)
}
if len(ancestors) != 1 {
t.Errorf("Expected 1 ancestor, got %d", len(ancestors))
}
}
func TestAddMemberIdToCard(t *testing.T) {
c := testCard(t)
c.client.BaseURL = mockResponse("cards", "card-add-member-response.json").URL
member, err := c.AddMemberID("testmemberid")
if err != nil {
t.Error(err)
}
if member[0].ID != "testmemberid" {
t.Errorf("Expected id testmemberid, got %v", member[0].ID)
}
if member[0].Username != "testmemberusername" {
t.Errorf("Expected username testmemberusername, got %v", member[0].Username)
}
}
// Utility function to get a simple response from Client.GetCard()
//
func testCard(t *testing.T) *Card {
c := testClient()
c.BaseURL = mockResponse("cards", "card-api-example.json").URL
card, err := c.GetCard("4eea503", Defaults())
if err != nil {
t.Fatal(err)
}
return card
}