forked from Teamwork/nylas-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
folder_test.go
99 lines (88 loc) · 2.14 KB
/
folder_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
package nylas
import (
"context"
"net/http"
"net/http/httptest"
"net/url"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFolders(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, "/folders")
assertQueryParams(t, r, wantQuery)
_, _ = w.Write(foldersJSON)
}))
defer ts.Close()
client := NewClient("", "", withTestServer(ts), WithAccessToken(accessToken))
got, err := client.Folders(context.Background(), &FoldersOptions{
Offset: 1,
Limit: 3,
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := []Folder{
{
ID: "4zv7p****",
Object: "folder",
Name: "inbox",
DisplayName: "INBOX",
AccountID: "awa6lt****",
},
{
ID: "76zrf****",
Name: "archive",
DisplayName: "2015 Archive",
AccountID: "awa6lto****",
Object: "folder",
},
}
if diff := cmp.Diff(got, want); diff != "" {
t.Errorf("Folders: (-got +want):\n%s", diff)
}
}
func TestFoldersCount(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, "/folders")
assertQueryParams(t, r, wantQuery)
_, _ = w.Write([]byte(`{"count":5}`))
}))
defer ts.Close()
client := NewClient("", "", withTestServer(ts), WithAccessToken(accessToken))
got, err := client.FoldersCount(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 foldersJSON = []byte(`[
{
"id": "4zv7p****",
"object": "folder",
"name": "inbox",
"display_name": "INBOX",
"account_id": "awa6lt****"
},
{
"id": "76zrf****",
"name": "archive",
"display_name": "2015 Archive",
"account_id": "awa6lto****",
"object": "folder"
}
]`)