@@ -11,7 +11,6 @@ import (
11
11
"testing"
12
12
13
13
"github.com/chris-ramon/golang-scaffolding/domain/auth/types"
14
- "github.com/julienschmidt/httprouter"
15
14
)
16
15
17
16
type testReaderError int
@@ -37,9 +36,8 @@ func TestGetPing(t *testing.T) {
37
36
h := NewHandlers (& serviceMock {})
38
37
req := httptest .NewRequest ("GET" , "/ping" , nil )
39
38
w := httptest .NewRecorder ()
40
- params := httprouter.Params {}
41
39
42
- h .GetPing ()(w , req , params )
40
+ h .GetPing ()(w , req )
43
41
44
42
body , err := io .ReadAll (w .Result ().Body )
45
43
if err != nil {
@@ -56,7 +54,6 @@ func TestGetCurrentUser(t *testing.T) {
56
54
srvMock * serviceMock
57
55
request * http.Request
58
56
responseWriter * httptest.ResponseRecorder
59
- params httprouter.Params
60
57
header http.Header
61
58
expectedBody string
62
59
expectedStatusCode uint
@@ -74,7 +71,6 @@ func TestGetCurrentUser(t *testing.T) {
74
71
},
75
72
request : httptest .NewRequest ("GET" , "/auth/current-user" , nil ),
76
73
responseWriter : httptest .NewRecorder (),
77
- params : httprouter.Params {},
78
74
header : map [string ][]string {
79
75
"Authorization" : []string {"Bearer Test-JWT-Token" },
80
76
},
@@ -86,7 +82,6 @@ func TestGetCurrentUser(t *testing.T) {
86
82
srvMock : & serviceMock {},
87
83
request : httptest .NewRequest ("GET" , "/auth/current-user" , nil ),
88
84
responseWriter : httptest .NewRecorder (),
89
- params : httprouter.Params {},
90
85
header : map [string ][]string {},
91
86
expectedBody : "failed to get authorization header" ,
92
87
expectedStatusCode : http .StatusInternalServerError ,
@@ -100,7 +95,6 @@ func TestGetCurrentUser(t *testing.T) {
100
95
},
101
96
request : httptest .NewRequest ("GET" , "/auth/current-user" , nil ),
102
97
responseWriter : httptest .NewRecorder (),
103
- params : httprouter.Params {},
104
98
header : map [string ][]string {
105
99
"Authorization" : []string {"Bearer Test-JWT-Token" },
106
100
},
@@ -119,7 +113,7 @@ func TestGetCurrentUser(t *testing.T) {
119
113
}
120
114
}
121
115
122
- h .GetCurrentUser ()(testCase .responseWriter , testCase .request , testCase . params )
116
+ h .GetCurrentUser ()(testCase .responseWriter , testCase .request )
123
117
124
118
if ! strings .Contains (testCase .responseWriter .Body .String (), testCase .expectedBody ) {
125
119
t .Fatalf ("expected: %v, got: %v" , testCase .expectedBody , testCase .responseWriter .Body .String ())
@@ -134,7 +128,6 @@ func TestPostSignIn(t *testing.T) {
134
128
srvMock * serviceMock
135
129
request * http.Request
136
130
responseWriter * httptest.ResponseRecorder
137
- params httprouter.Params
138
131
expectedBody string
139
132
}
140
133
@@ -154,7 +147,6 @@ func TestPostSignIn(t *testing.T) {
154
147
bytes .
NewBuffer ([]
byte (
`{"email":"[email protected] ","password":"test-pwd"}` )),
155
148
),
156
149
responseWriter : httptest .NewRecorder (),
157
- params : httprouter.Params {},
158
150
expectedBody : "test user" ,
159
151
},
160
152
{
@@ -172,7 +164,6 @@ func TestPostSignIn(t *testing.T) {
172
164
testReaderError (0 ),
173
165
),
174
166
responseWriter : httptest .NewRecorder (),
175
- params : httprouter.Params {},
176
167
expectedBody : "failed to read request body" ,
177
168
},
178
169
{
@@ -190,7 +181,6 @@ func TestPostSignIn(t *testing.T) {
190
181
bytes .NewBuffer ([]byte (`{invalid}` )),
191
182
),
192
183
responseWriter : httptest .NewRecorder (),
193
- params : httprouter.Params {},
194
184
expectedBody : "failed to json unmarshal request body" ,
195
185
},
196
186
{
@@ -206,15 +196,14 @@ func TestPostSignIn(t *testing.T) {
206
196
bytes .
NewBuffer ([]
byte (
`{"email":"[email protected] ","password":"test-pwd"}` )),
207
197
),
208
198
responseWriter : httptest .NewRecorder (),
209
- params : httprouter.Params {},
210
199
expectedBody : "failed to find current user" ,
211
200
},
212
201
}
213
202
214
203
for _ , testCase := range testCases {
215
204
t .Run (testCase .name , func (t * testing.T ) {
216
205
h := NewHandlers (testCase .srvMock )
217
- h .PostSignIn ()(testCase .responseWriter , testCase .request , testCase . params )
206
+ h .PostSignIn ()(testCase .responseWriter , testCase .request )
218
207
if ! strings .Contains (testCase .responseWriter .Body .String (), testCase .expectedBody ) {
219
208
t .Fatalf ("expected: %v, got: %v" , testCase .expectedBody , testCase .responseWriter .Body .String ())
220
209
}
0 commit comments