forked from VojtechVitek/go-trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_test.go
199 lines (166 loc) · 5.46 KB
/
board_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
/*
Copyright 2014 go-trello authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package trello
import (
"fmt"
"log"
"testing"
"time"
goblin "github.com/franela/goblin"
. "github.com/onsi/gomega"
)
func TestBoard(t *testing.T) {
g := goblin.Goblin(t)
RegisterFailHandler(func(m string, _ ...int) { g.Fail(m) })
g.Describe("Board tests", func() {
var board *Board
var member *Member
var label *Label
var testBoardName string
g.Before(func() {
testBoardName = fmt.Sprintf("GoTestTrello-Board-%v", time.Now().Unix())
board, err = client.CreateBoard(testBoardName)
if err != nil || board == nil {
log.Fatal("ERROR Creating Board: " + err.Error())
}
member, err = client.Member("trello")
if err != nil || member == nil {
log.Fatal("ERROR Retrieving 'trello' member: " + err.Error())
}
})
g.It("should get a board by ID", func() {
b, err := client.Board(board.ID)
Expect(err).To(BeNil())
Expect(b).NotTo(BeNil())
Expect(b.Name).To(Equal(testBoardName))
})
g.It("should change the board background to red", func() {
err = board.SetBackground("red")
Expect(err).To(BeNil())
Expect(board.Prefs.Background).To(Equal("red"))
})
g.It("should change the description to something", func() {
err = board.SetDescription("something")
Expect(err).To(BeNil())
Expect(board.Desc).To(Equal("something"))
})
g.It("should get the members of a board", func() {
members, err := board.GetMembers()
Expect(err).To(BeNil())
Expect(members).NotTo(BeNil())
})
// This needs to come before "AddMember" for code coverage reasons
g.It("should get memberships on a board", func() {
ms, err := board.GetMemberships()
Expect(err).To(BeNil())
Expect(len(ms)).To(BeNumerically(">", 0))
})
g.It("should add a member (trello) to a board", func() {
err := board.AddMember(member, "")
Expect(err).To(BeNil())
// TODO: Check to be sure trello *is* a member, for now this should work
})
g.It("should check to see if member is an admin", func() {
isAdmin := board.IsAdmin(member)
Expect(isAdmin).To(BeFalse())
})
g.It("should check to see if an invalid member is an admin", func() {
invalidMember, err := client.Member("test")
Expect(err).To(BeNil())
Expect(invalidMember).NotTo(BeNil())
isAdmin := board.IsAdmin(invalidMember)
Expect(isAdmin).To(BeFalse())
})
g.It("should check to see if itself (me) is an admin", func() {
me, err := client.Member("me")
Expect(err).To(BeNil())
Expect(me).NotTo(BeNil())
isAdmin := board.IsAdmin(me)
Expect(isAdmin).To(BeTrue())
})
g.It("should remove a member from a board", func() {
g.Timeout(10 * time.Second) // The delete seems to take longer than 5 seconds
err := board.RemoveMember(member)
Expect(err).To(BeNil())
// TODO: Check to be sure trello is *not* a member, for now this should work
})
g.It("should get the members of a board (after adding/removing)", func() {
members, err := board.GetMembers()
Expect(err).To(BeNil())
Expect(members).NotTo(BeNil())
})
g.It("should get the lists in a board", func() {
lists, err := board.Lists()
Expect(err).To(BeNil())
// This part is somewhat dangerous if Trello changes the default Board Template
Expect(lists[0].Name).To(Equal("To Do"))
Expect(lists[1].Name).To(Equal("Doing"))
Expect(lists[2].Name).To(Equal("Done"))
})
g.It("should get all the actions in a board", func() {
_, err := board.Actions()
Expect(err).To(BeNil())
})
g.It("should get filtered actions in a board", func() {
arg := NewArgument("filter", "addMemberToCard")
_, err := board.Actions(arg)
Expect(err).To(BeNil())
})
g.It("should add a list to a board", func() {
list, err := board.AddList(List{
Name: "go-test",
})
Expect(err).To(BeNil())
Expect(list.Name).To(BeEquivalentTo("go-test"))
Expect(list.IDBoard).To(Equal(board.ID))
})
g.It("should get the labels in a board", func() {
_, err := board.Labels()
Expect(err).To(BeNil())
})
g.It("should add a label to a board", func() {
label, err = board.AddLabel("go-testing", "orange")
Expect(err).To(BeNil())
Expect(label.Name).To(Equal("go-testing"))
Expect(label.Color).To(Equal("orange"))
})
g.It("should update a label name", func() {
err = label.SetName("super-go-testing")
Expect(err).To(BeNil())
})
g.It("should update a label color", func() {
err = label.SetColor("purple")
Expect(err).To(BeNil())
})
g.It("should delete a label", func() {
err = label.Delete()
Expect(err).To(BeNil())
})
g.It("should duplicate (copy) the board", func() {
new, err := board.Duplicate("DUP-"+testBoardName, true)
Expect(err).To(BeNil())
Expect(new).NotTo(BeNil())
Expect(new.ID).NotTo(Equal(board.ID))
// and cleanup
err = new.Delete()
Expect(err).To(BeNil())
})
// Keep this test LAST for obvious reasons
g.After(func() {
err = board.Delete()
if err != nil {
log.Fatal("ERROR Deleting Board: " + err.Error())
}
})
})
}