forked from adlio/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_test.go
86 lines (77 loc) · 1.98 KB
/
list_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
// 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 TestListCreatedAt(t *testing.T) {
l := List{ID: "4d5ea62fd76aa1136000000c"}
ts := l.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 TestGetList(t *testing.T) {
list := testList(t)
if list.Name != "To Do Soon" {
t.Errorf("Title incorrect. Got '%s'", list.Name)
}
}
func TestGetListWithCards(t *testing.T) {
c := testClient()
c.BaseURL = mockResponse("lists", "list-api-example.json").URL
list, err := c.GetList("4eea4ff", Defaults())
if err != nil {
t.Fatal(err)
}
if len(list.Cards) == 0 {
t.Fatal("cannot test cards as non was available in lists mock response")
}
if list.Cards[0].client == nil {
t.Fatal("client not set on cards")
}
}
func TestGetListsOnBoard(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("lists", "board-lists-api-example.json").URL
lists, err := board.GetLists(Defaults())
if err != nil {
t.Fatal(err)
}
if len(lists) != 3 {
t.Errorf("Expected 1 list, got %d", len(lists))
}
}
func TestGetListsOnBoardWithCards(t *testing.T) {
board := testBoard(t)
board.client.BaseURL = mockResponse("lists", "board-lists-api-example.json").URL
lists, err := board.GetLists(Defaults())
if err != nil {
t.Fatal(err)
}
for i := range lists {
if len(lists[i].Cards) == 0 {
t.Fatal("cannot test cards as non was available in lists mock response")
}
if lists[i].Cards[0].client == nil {
t.Fatal("client not set on cards")
}
}
}
// Utility function to get the standard case Client.GetList() response
//
func testList(t *testing.T) *List {
c := testClient()
c.BaseURL = mockResponse("lists", "list-api-example.json").URL
list, err := c.GetList("4eea4ff", Defaults())
if err != nil {
t.Fatal(err)
}
return list
}