-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_test.go
147 lines (117 loc) · 3.2 KB
/
group_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
package docbase
import (
"fmt"
"github.com/hayashiki/docbase-go/testutil"
"net/http"
"reflect"
"testing"
"time"
)
func TestGroupService_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/groups", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, testutil.LoadFixture(t, "group-list-response.json"))
})
group1 := SimpleGroup{
ID: 1,
Name: "DocBase",
}
group2 := SimpleGroup{
ID: 2,
Name: "kray-internal",
}
opts := &GroupListOptions{
PerPage: 5,
Page: 1,
Name: "query",
}
groups, resp, err := client.Groups.List(opts)
want := &GroupListResponse{group1, group2}
if err != nil {
t.Errorf("Shouldn't have returned an error: %+v", err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Comment Create request code = %v, expected %v", resp.StatusCode, http.StatusOK)
}
if !reflect.DeepEqual(groups, want) {
t.Errorf("GroupList returned %+v, want %+v", groups, want)
}
}
func TestGroupService_Get(t *testing.T) {
setup()
defer teardown()
ti, err := time.Parse(time.RFC3339, "2020-03-27T09:25:09+09:00")
if err != nil {
t.Errorf("Fail to parse err: %v", err)
}
expect := &Group{
ID: 1,
Name: "グループ1",
Description: "APIで作ったグループ",
PostsCount: 0,
LastActivityAt: ti,
CreatedAt: ti,
Users: []SimpleUser{
SimpleUser{
ID: 1,
Name: "docbaseman",
ProfileImageURL: "https://image.docbase.io/uploads/aaa.gif",
},
},
}
mux.HandleFunc(fmt.Sprintf("/groups/%d", expect.ID), func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, testutil.LoadFixture(t, "group-response.json"))
})
group, resp, err := client.Groups.Get(expect.ID)
if err != nil {
t.Errorf("Fail to get group request err: %v", err)
}
if resp.StatusCode != http.StatusOK {
t.Errorf("Upload attachment response code = %v, expected %v", resp.StatusCode, http.StatusOK)
}
if !reflect.DeepEqual(group, expect) {
t.Errorf("Group returned %+v, want %+v", group, expect)
}
}
func TestGroupCli_Create(t *testing.T) {
setup()
defer teardown()
createRequest := &GroupCreateRequest{
Name: "DocBase",
Description: "DocBase",
}
mux.HandleFunc("/groups", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusCreated)
testMethod(t, r, "POST")
fmt.Fprint(w, testutil.LoadFixture(t, "group-response.json"))
})
group, resp, err := client.Groups.Create(createRequest)
if err != nil {
t.Errorf("Fail to create group request err: %v", err)
}
if resp.StatusCode != http.StatusCreated {
t.Errorf("Create group response code = %v, expected %v", resp.StatusCode, http.StatusCreated)
}
ti, err := time.Parse(time.RFC3339, "2020-03-27T09:25:09+09:00")
want := &Group{
ID: 1,
Name: "グループ1",
Description: "APIで作ったグループ",
PostsCount: 0,
LastActivityAt: ti,
CreatedAt: ti,
Users: []SimpleUser{
SimpleUser{
ID: 1,
Name: "docbaseman",
ProfileImageURL: "https://image.docbase.io/uploads/aaa.gif",
},
},
}
// TODO
if !reflect.DeepEqual(want, group) {
t.Errorf("Request response: %+v, want %+v", group, want)
}
}