forked from jomei/notionapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authentication_test.go
72 lines (67 loc) · 1.87 KB
/
authentication_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
package notionapi_test
import (
"context"
"net/http"
"reflect"
"testing"
"github.com/jomei/notionapi"
)
func TestAuthenticationClient(t *testing.T) {
t.Run("CreateToken", func(t *testing.T) {
tests := []struct {
name string
filePath string
statusCode int
request *notionapi.TokenCreateRequest
want *notionapi.TokenCreateResponse
wantErr error
}{
{
name: "Creates token",
filePath: "testdata/create_token.json",
statusCode: http.StatusOK,
request: ¬ionapi.TokenCreateRequest{
Code: "code1",
GrantType: "authorization_code",
RedirectUri: "www.example.com",
},
want: ¬ionapi.TokenCreateResponse{
AccessToken: "token1",
BotId: "bot1",
DuplicatedTemplateId: "template_id1",
WorkspaceIcon: "🎉",
WorkspaceId: "workspaceid_1",
WorkspaceName: "workspace_1",
},
wantErr: nil,
},
{
name: "Creates token",
filePath: "testdata/create_token_error.json",
statusCode: http.StatusBadRequest,
request: ¬ionapi.TokenCreateRequest{
Code: "code1",
GrantType: "authorization_code",
RedirectUri: "www.example.com",
},
wantErr: ¬ionapi.TokenCreateError{
Code: "invalid_grant",
Message: "Invalid code.",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := newMockedClient(t, tt.filePath, tt.statusCode)
client := notionapi.NewClient("some_token", notionapi.WithHTTPClient(c))
got, gotErr := client.Authentication.CreateToken(context.Background(), tt.request)
if !reflect.DeepEqual(gotErr, tt.wantErr) {
t.Errorf("Query() gotErr = %v, wantErr %v", gotErr, tt.wantErr)
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Query() got = %v, want %v", got, tt.want)
}
})
}
})
}