forked from AkihikoITOH/wrike.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_groups_test.go
161 lines (148 loc) · 4.03 KB
/
query_groups_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
package wrike_test
import (
"fmt"
"net/http"
"net/url"
"testing"
"gotest.tools/assert"
wrike "github.com/wingman131/wrike.go"
"github.com/wingman131/wrike.go/parameters"
)
var groupData = []byte(
`{
"kind": "groups",
"data":
[
{
"id": "KX77777H",
"accountId": "IEAAAAAQ",
"title": "New test group",
"memberIds":
[
"KUAAAAAQ"
],
"childIds":
[
"KX77777G"
],
"parentIds":
[
"KX77777I"
],
"avatarUrl": "/D5/E6/Circle_ffc5cbd9_78-71_v1.png"
}
]
}`)
var allGroupsData = []byte(
`{
"kind": "groups",
"data":
[
{
"id": "KX77777G",
"accountId": "IEAAAAAQ",
"title": "Test child group",
"memberIds":
[
],
"childIds":
[
],
"parentIds":
[
"KX77777H"
],
"avatarUrl": "/D5/48/Circle_ff80cbc4_84-67_v1.png"
},
{
"id": "KX77777H",
"accountId": "IEAAAAAQ",
"title": "New test group",
"memberIds":
[
"KUAAAAAQ"
],
"childIds":
[
"KX77777G"
],
"parentIds":
[
"KX77777I"
],
"avatarUrl": "/D5/E6/Circle_ffc5cbd9_78-71_v1.png"
},
{
"id": "KX77777I",
"accountId": "IEAAAAAQ",
"title": "Test parent group",
"memberIds":
[
],
"childIds":
[
"KX77777H"
],
"parentIds":
[
],
"avatarUrl": "/4C/D1/Circle_fff48fb1_84-80_v1.png"
}
]
}`)
func NewQueryGroupParams() parameters.QueryGroup {
return parameters.QueryGroup{Fields: ¶meters.FieldSet{"metadata"}}
}
func NewQueryGroupsParams() parameters.QueryGroups {
return parameters.QueryGroups{
Fields: ¶meters.FieldSet{"metadata"},
Metadata: ¶meters.Metadata{Key: "Test Key", Value: "Test Value"},
}
}
func Example_queryGroup() {
conf := wrike.NewConfig("wrike-access-token", "")
api := wrike.NewAPI(conf)
params := parameters.QueryGroup{Fields: ¶meters.FieldSet{"metadata"}}
api.QueryGroup("KX77777H", ¶ms)
}
func Example_queryGroups() {
conf := wrike.NewConfig("wrike-access-token", "")
api := wrike.NewAPI(conf)
params := parameters.QueryGroups{
Fields: ¶meters.FieldSet{"metadata"},
Metadata: ¶meters.Metadata{Key: "Test Key", Value: "Test Value"},
}
api.QueryGroups(¶ms)
}
func TestQueryGroup(t *testing.T) {
client := NewMockClient(groupData)
api := &wrike.API{Config: mockAPIConfig, HTTPClient: client}
params := NewQueryGroupParams()
groups, err := api.QueryGroup("KX77777H", ¶ms)
if err != nil {
fmt.Println(err.Error())
}
// Check request object
assert.Equal(t, client.Request.Method, http.MethodGet)
data, _ := url.QueryUnescape(client.Request.URL.String())
assert.Equal(t, data, "https://app-eu.wrike.com/api/v4/groups/KX77777H?fields=[\"metadata\"]")
assert.Equal(t, client.Request.Body, nil)
SharedRequestTests(t, client.Request)
assert.Equal(t, string(groups.Data[0].ID), "KX77777H")
}
func TestQueryGroups(t *testing.T) {
client := NewMockClient(allGroupsData)
api := &wrike.API{Config: mockAPIConfig, HTTPClient: client}
params := NewQueryGroupsParams()
groups, err := api.QueryGroups(¶ms)
if err != nil {
fmt.Println(err.Error())
}
// Check request object
assert.Equal(t, client.Request.Method, http.MethodGet)
data, _ := url.QueryUnescape(client.Request.URL.String())
assert.Equal(t, data, "https://app-eu.wrike.com/api/v4/groups?fields=[\"metadata\"]&metadata={\"key\":\"Test Key\",\"value\":\"Test Value\"}")
assert.Equal(t, client.Request.Body, nil)
SharedRequestTests(t, client.Request)
assert.Equal(t, len(groups.Data), 3)
}