-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuser_testdata_test.go
81 lines (74 loc) · 2.35 KB
/
user_testdata_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
// Copyright (c) 2019 Faye Amacker. All rights reserved.
// Use of this source code is governed by Apache License 2.0 found in the LICENSE file.
package main
import (
"net/http"
)
var (
logoutSuccessResponse = `{
"status": "ok",
"errorMessage": ""
}`
userSuccessResponse = `{
"status": "ok",
"name": "johndoe@example.com",
"displayName": "John Doe",
"CredentialID": "LFdoCFJTyB82ZzSJUHc-c72yraRc_1mPvGX8ToE8su39xX26Jcqd31LUkKOS36FIAWgWl6itMKqmDvruha6ywA",
"RegisteredAt": "2009-11-10 23:00:00 +0000 UTC",
"LoggedInAt": "2009-11-10 23:00:00 +0000 UTC"
}`
userErrorResponse = `{
"status": "failed",
"errorMessage": "User is not logged in"
}`
logoutTests = handlerTest{
requestMethod: "GET",
requestURL: "/logout",
equalResponseBody: equalServerResponse,
testcases: []handlerTestData{
{
name: "user is not logged in",
server: getMockServer(),
initMockDataStore: nil,
initMockSessionStore: initSessionStore(getEmptySession, getEmptySession),
requestBody: "",
wantStatusCode: http.StatusOK,
wantResponseBody: logoutSuccessResponse,
},
{
name: "user is logged in",
server: getMockServer(),
initMockDataStore: nil,
initMockSessionStore: initSessionStore(getUserSession, getEmptySession),
requestBody: "",
wantStatusCode: http.StatusOK,
wantResponseBody: logoutSuccessResponse,
},
},
}
userTests = handlerTest{
requestMethod: "GET",
requestURL: "/user",
equalResponseBody: equalServerResponse,
testcases: []handlerTestData{
{
name: "user is not logged in",
server: getMockServer(),
initMockDataStore: initDataStoreGetCredentialTimestamp,
initMockSessionStore: initSessionStore(getEmptySession, getEmptySession),
requestBody: "",
wantStatusCode: http.StatusUnauthorized,
wantResponseBody: userErrorResponse,
},
{
name: "user is logged in",
server: getMockServer(),
initMockDataStore: initDataStoreGetCredentialTimestamp,
initMockSessionStore: initSessionStore(getUserSession, getUserSession),
requestBody: "",
wantStatusCode: http.StatusOK,
wantResponseBody: userSuccessResponse,
},
},
}
)