-
Notifications
You must be signed in to change notification settings - Fork 4
/
query_accounts_test.go
127 lines (119 loc) · 3.59 KB
/
query_accounts_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
package wrike_test
import (
"fmt"
"net/http"
"net/url"
"testing"
"gotest.tools/assert"
wrike "github.com/AkihikoITOH/wrike.go"
"github.com/AkihikoITOH/wrike.go/parameters"
"github.com/AkihikoITOH/wrike.go/types"
)
var allAccountsData = []byte(
`{
"kind": "accounts",
"data":
[
{
"id": "IEAAAAAQ",
"name": "Account",
"dateFormat": "MM/dd/yyyy",
"firstDayOfWeek": "Mon",
"workDays":
[
"Mon",
"Tue",
"Wed"
],
"rootFolderId": "IEAAAAAQI7777777",
"recycleBinId": "IEAAAAAQI7777776",
"createdDate": "2019-02-11T09:45:40Z",
"subscription":
{
"type": "Enterprise",
"paid": false,
"userLimit": 50
},
"metadata":
[
{
"key": "testMetaKey",
"value": "testMetaValue"
}
],
"customFields":
[
{
"id": "IEAAAAAQJUAAAAAP",
"accountId": "IEAAAAAQ",
"title": "test 1",
"type": "Text",
"sharedIds":
[
],
"settings":
{
"inheritanceType": "All"
}
},
{
"id": "IEAAAAAQJUAAAAAQ",
"accountId": "IEAAAAAQ",
"title": "test 2",
"type": "Text",
"sharedIds":
[
],
"settings":
{
"inheritanceType": "All"
}
},
{
"id": "IEAAAAAQJUAAAAAT",
"accountId": "IEAAAAAQ",
"title": "test 1",
"type": "Text",
"sharedIds":
[
],
"settings":
{
"inheritanceType": "All"
}
}
],
"joinedDate": "2019-02-11T09:45:40Z"
}
]
}`)
func NewQueryAccountsParams() parameters.QueryAccounts {
return parameters.QueryAccounts{
Fields: ¶meters.FieldSet{types.CustomFieldsField, types.SubscriptionField, types.MetadataField},
}
}
func Example_queryAccounts() {
conf := wrike.NewConfig("wrike-access-token", "")
api := wrike.NewAPI(conf)
params := parameters.QueryAccounts{
Fields: ¶meters.FieldSet{types.CustomFieldsField, types.SubscriptionField, types.MetadataField},
}
api.QueryAccounts(¶ms)
}
func TestQueryAccounts(t *testing.T) {
client := NewMockClient(allAccountsData)
api := &wrike.API{Config: mockAPIConfig, HTTPClient: client}
params := NewQueryAccountsParams()
accounts, err := api.QueryAccounts(¶ms)
if err != nil {
fmt.Println(err.Error())
}
// Check request object
assert.Equal(t, client.Request.Method, http.MethodGet)
urlStr, _ := url.QueryUnescape(client.Request.URL.String())
assert.Equal(t, urlStr, "https://app-eu.wrike.com/api/v4/account?fields=[\"customFields\",\"subscription\",\"metadata\"]")
assert.Equal(t, client.Request.Body, nil)
SharedRequestTests(t, client.Request)
assert.Equal(t, len(accounts.Data), 1)
assert.Equal(t, string(accounts.Data[0].ID), "IEAAAAAQ")
}