-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhandler_test.go
More file actions
155 lines (126 loc) · 4.56 KB
/
handler_test.go
File metadata and controls
155 lines (126 loc) · 4.56 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"github.com/Muxi-X/muxi_auth_service_v2/handler"
"github.com/Muxi-X/muxi_auth_service_v2/handler/signin"
"github.com/Muxi-X/muxi_auth_service_v2/handler/signup"
"github.com/Muxi-X/muxi_auth_service_v2/pkg/constvar"
"github.com/Muxi-X/muxi_auth_service_v2/util"
"github.com/stretchr/testify/assert"
"encoding/base64"
"net/http"
"net/http/httptest"
"testing"
)
func Test_B_SignUp(t *testing.T) {
signupMock := signup.UserSignupRequestData{
Username: "testMockUser2",
Email: "testUser2@mock.com",
Password: base64.StdEncoding.EncodeToString([]byte("testMockPassword2")),
}
w := util.SendTestRequest("POST", "/auth/api/signup", signupMock)
assert.Equal(t, 200, w.Code)
assert.Equal(t, 0, util.GetCodeFromError(t, w.Body.Bytes()))
}
func Test_C_A_SignIn(t *testing.T) {
signinMock := signin.UserSigninRequestData{
Username: "testMockUser2",
Password: base64.StdEncoding.EncodeToString([]byte("testMockPassword2")),
}
w := util.SendTestRequest("POST", "/auth/api/signin", signinMock)
assert.Equal(t, 0, util.GetCodeFromError(t, w.Body.Bytes()))
var data handler.Response
constvar.Token = util.GetValueFromResponse(t, w.Body.Bytes(), data, "token").(string)
}
func Test_C_B_Signin(t *testing.T) {
signinMock := signin.UserSigninRequestData{
Username: "testMockUser2",
Password: base64.StdEncoding.EncodeToString([]byte("testMoooooockPassword2")),
}
w := util.SendTestRequest("POST", "/auth/api/signin", signinMock)
assert.Equal(t, 20301, util.GetCodeFromError(t, w.Body.Bytes()))
}
func Test_C_C_Signin(t *testing.T) {
signinMock := signin.UserSigninRequestData{
Username: "testMo00000ckUser2",
Password: base64.StdEncoding.EncodeToString([]byte("testMoooooockPassword2")),
}
w := util.SendTestRequest("POST", "/auth/api/signin", signinMock)
assert.Equal(t, 20102, util.GetCodeFromError(t, w.Body.Bytes()))
}
func Test_D_A_CheckEmail(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/check_email", nil)
query := req.URL.Query()
query.Add("email", "testUser2@mock.com")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
var data handler.Response
result := util.GetValueFromResponse(t, w.Body.Bytes(), data, "").(bool)
assert.Equal(t, true, result)
}
func Test_D_B_CheckEmail(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/check_email", nil)
query := req.URL.Query()
query.Add("email", "testUser2@mmm.com")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
var data handler.Response
result := util.GetValueFromResponse(t, w.Body.Bytes(), data, "").(bool)
assert.Equal(t, false, result)
}
func Test_E_A_CheckUsername(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/check_name", nil)
query := req.URL.Query()
query.Add("username", "testMockUser2")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
var data handler.Response
result := util.GetValueFromResponse(t, w.Body.Bytes(), data, "").(bool)
assert.Equal(t, true, result)
}
func Test_E_B_CheckUsername(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/check_name", nil)
query := req.URL.Query()
query.Add("username", "testMmmUser2")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
var data handler.Response
result := util.GetValueFromResponse(t, w.Body.Bytes(), data, "").(bool)
assert.Equal(t, false, result)
}
func Test_F_CheckToken(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/check_token", nil)
query := req.URL.Query()
query.Add("email", "testUser2@mock.com")
query.Add("token", constvar.Token)
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
}
func Test_G_A_GetEmailByName(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/email", nil)
query := req.URL.Query()
query.Add("username", "testMockUser2")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
}
func Test_G_B_GetEmailByName(t *testing.T) {
w := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/auth/api/email", nil)
query := req.URL.Query()
query.Add("username", "testMmmUser2")
req.URL.RawQuery = query.Encode()
constvar.TestRouter.ServeHTTP(w, req)
assert.Equal(t, 200, w.Code)
assert.Equal(t, 20102, util.GetCodeFromError(t, w.Body.Bytes()))
}