forked from AkihikoITOH/wrike.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_group_test.go
97 lines (89 loc) · 2.8 KB
/
modify_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
package wrike_test
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"testing"
"gotest.tools/assert"
wrike "github.com/wingman131/wrike.go"
"github.com/wingman131/wrike.go/parameters"
)
var modifiedGroupData = []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",
"metadata":
[
{
"key": "testMetaKey",
"value": "testMetaValue"
}
]
}
]
}`)
func NewModifyGroupParams() parameters.ModifyGroup {
title := "New test group"
parent := "KX77777I"
params := parameters.ModifyGroup{
Title: &title,
AddMembers: parameters.ContactIDSet{"KUAAAAAQ"},
RemoveMembers: parameters.ContactIDSet{"KUAAAAHK"},
Parent: &parent,
Avatar: ¶meters.Avatar{Letters: "NG", Color: "#c5cbd9"},
Metadata: ¶meters.MetadataSet{parameters.Metadata{Key: "testMetaKey", Value: "testMetaValue"}},
}
return params
}
func Example_modifyGroup() {
conf := wrike.NewConfig("wrike-access-token", "")
api := wrike.NewAPI(conf)
title := "New test group"
parent := "KX77777I"
params := parameters.ModifyGroup{
Title: &title,
AddMembers: parameters.ContactIDSet{"KUAAAAAQ"},
RemoveMembers: parameters.ContactIDSet{"KUAAAAHK"},
Parent: &parent,
Avatar: ¶meters.Avatar{Letters: "NG", Color: "#c5cbd9"},
Metadata: ¶meters.MetadataSet{parameters.Metadata{Key: "testMetaKey", Value: "testMetaValue"}},
}
api.ModifyGroup("KX77777H", ¶ms)
}
func TestModifyGroup(t *testing.T) {
id := "KX77777H"
client := NewMockClient(modifiedGroupData)
api := &wrike.API{Config: mockAPIConfig, HTTPClient: client}
params := NewModifyGroupParams()
group, err := api.ModifyGroup(id, ¶ms)
if err != nil {
fmt.Println(err.Error())
}
// Check request object
assert.Equal(t, client.Request.Method, http.MethodPut)
assert.Equal(t, client.Request.URL.String(), "https://app-eu.wrike.com/api/v4/groups/KX77777H")
body, _ := ioutil.ReadAll(client.Request.Body)
data, _ := url.QueryUnescape(string(body))
assert.Equal(t, data, "addMembers=[\"KUAAAAAQ\"]&avatar={\"letters\":\"NG\",\"color\":\"#c5cbd9\"}&metadata=[{\"key\":\"testMetaKey\",\"value\":\"testMetaValue\"}]&parent=KX77777I&removeMembers=[\"KUAAAAHK\"]&title=New test group")
SharedRequestTests(t, client.Request)
assert.Equal(t, string(group.Data[0].ID), "KX77777H")
}