forked from Teamwork/nylas-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel_test.go
113 lines (102 loc) · 2.57 KB
/
label_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
package nylas
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestLabels(t *testing.T) {
accessToken := "accessToken"
wantQuery := url.Values{
"limit": {"3"},
"offset": {"1"},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assertBasicAuth(t, r, accessToken, "")
assertMethodPath(t, r, http.MethodGet, "/labels")
assertQueryParams(t, r, wantQuery)
_, _ = w.Write(labelsJSON)
}))
defer ts.Close()
client := NewClient("", "", withTestServer(ts), WithAccessToken(accessToken))
got, err := client.Labels(context.Background(), &LabelsOptions{
Offset: 1,
Limit: 3,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := []Label{
{
AccountID: "crkr5ct7aa3edvipotb****",
DisplayName: "Inbox",
ID: "atamsqdb355jqyj0zhhatu3ao",
Name: "inbox",
Object: "label",
},
{
AccountID: "crkr5ct7aa3edvipotb****",
DisplayName: "Trash",
ID: "558oz6v9e558so4najbpaonn8",
Name: "trash",
Object: "label",
},
{
AccountID: "crkr5ct7aa3edvipotb****",
DisplayName: "Sent Mail",
ID: "3myg0x7i45lkn5xmel3m9d3v1",
Name: "sent",
Object: "label",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Labels: (-got +want):\n%s", diff)
}
}
func TestLabelsCount(t *testing.T) {
accessToken := "accessToken"
wantQuery := url.Values{
"view": {ViewCount},
}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assertBasicAuth(t, r, accessToken, "")
assertMethodPath(t, r, http.MethodGet, "/labels")
assertQueryParams(t, r, wantQuery)
_, _ = w.Write([]byte(`{"count":5}`))
}))
defer ts.Close()
client := NewClient("", "", withTestServer(ts), WithAccessToken(accessToken))
got, err := client.LabelsCount(context.Background())
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := 5
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("count: (-got +want):\n%s", diff)
}
}
var labelsJSON = []byte(`[
{
"account_id": "crkr5ct7aa3edvipotb****",
"display_name": "Inbox",
"id": "atamsqdb355jqyj0zhhatu3ao",
"name": "inbox",
"object": "label"
},
{
"account_id": "crkr5ct7aa3edvipotb****",
"display_name": "Trash",
"id": "558oz6v9e558so4najbpaonn8",
"name": "trash",
"object": "label"
},
{
"account_id": "crkr5ct7aa3edvipotb****",
"display_name": "Sent Mail",
"id": "3myg0x7i45lkn5xmel3m9d3v1",
"name": "sent",
"object": "label"
}
]`)