forked from AkihikoITOH/wrike.go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify_custom_field_test.go
86 lines (78 loc) · 2.36 KB
/
modify_custom_field_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
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"
"github.com/wingman131/wrike.go/types"
)
var modifiedCustomFieldData = []byte(
`{
"kind": "customfields",
"data":
[
{
"id": "IEAAAAX3JUAAAAHL",
"accountId": "IEAAAAX3",
"title": "New test custom field",
"type": "Numeric",
"sharedIds":
[
"KUAAAA3E"
],
"settings":
{
"inheritanceType": "All",
"decimalPlaces": 2,
"useThousandsSeparator": false,
"aggregation": "Sum"
}
}
]
}`)
func NewModifyCustomFieldParams() parameters.ModifyCustomField {
title := "New test custom field"
typ := types.NumericType
params := parameters.ModifyCustomField{
AddShareds: parameters.ContactIDSet{"KUAAAA3E"},
RemoveShareds: parameters.ContactIDSet{"KUAAAA3F"},
Title: &title,
Type: &typ,
}
return params
}
func Example_modifyCustomField() {
conf := wrike.NewConfig("wrike-access-token", "")
api := wrike.NewAPI(conf)
title := "New test custom field"
typ := types.NumericType
params := parameters.ModifyCustomField{
AddShareds: parameters.ContactIDSet{"KUAAAA3E"},
RemoveShareds: parameters.ContactIDSet{"KUAAAA3F"},
Title: &title,
Type: &typ,
}
api.ModifyCustomField("IEAAAAX3JUAAAAHL", ¶ms)
}
func TestModifyCustomField(t *testing.T) {
id := "IEAAAAX3JUAAAAHL"
client := NewMockClient(modifiedCustomFieldData)
api := &wrike.API{Config: mockAPIConfig, HTTPClient: client}
params := NewModifyCustomFieldParams()
custom_field, err := api.ModifyCustomField(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/customfields/IEAAAAX3JUAAAAHL")
body, _ := ioutil.ReadAll(client.Request.Body)
data, _ := url.QueryUnescape(string(body))
assert.Equal(t, data, "addShareds=[\"KUAAAA3E\"]&removeShareds=[\"KUAAAA3F\"]&title=New test custom field&type=Numeric")
SharedRequestTests(t, client.Request)
assert.Equal(t, string(custom_field.Data[0].ID), "IEAAAAX3JUAAAAHL")
}