11package api
22
33import (
4+ "fmt"
45 "net/http/httptest"
56 "net/url"
67 "strings"
@@ -165,7 +166,7 @@ func (s *ClientSuite) Test_DeleteClient_expectNotFound() {
165166
166167 test .WithUser (s .ctx , 5 )
167168 s .ctx .Request = httptest .NewRequest ("DELETE" , "/token/" + firstClientToken , nil )
168- s .ctx .Params = gin. Params {{ Key : "id" , Value : "8" }}
169+ s .ctx .AddParam ( "id" , "8" )
169170
170171 s .a .DeleteClient (s .ctx )
171172
@@ -177,7 +178,7 @@ func (s *ClientSuite) Test_DeleteClient() {
177178
178179 test .WithUser (s .ctx , 5 )
179180 s .ctx .Request = httptest .NewRequest ("DELETE" , "/token/" + firstClientToken , nil )
180- s .ctx .Params = gin. Params {{ Key : "id" , Value : "8" }}
181+ s .ctx .AddParam ( "id" , "8" )
181182
182183 assert .False (s .T (), s .notified )
183184
@@ -228,7 +229,7 @@ func (s *ClientSuite) Test_ElevateClient_expectSuccess() {
228229 s .db .User (5 ).Client (8 )
229230
230231 test .WithUser (s .ctx , 5 )
231- s .withJSONBody ( `{"id":8,"durationSeconds": 900}` )
232+ s .withElevateRequest ( 8 , 900 )
232233
233234 before := time .Now ()
234235 s .a .ElevateClient (s .ctx )
@@ -245,7 +246,7 @@ func (s *ClientSuite) Test_ElevateClient_expectNotFoundOnMissingClient() {
245246 s .db .User (5 )
246247
247248 test .WithUser (s .ctx , 5 )
248- s .withJSONBody ( `{"id":8,"durationSeconds": 900}` )
249+ s .withElevateRequest ( 8 , 900 )
249250
250251 s .a .ElevateClient (s .ctx )
251252
@@ -257,7 +258,7 @@ func (s *ClientSuite) Test_ElevateClient_expectNotFoundOnCurrentUserIsNotOwner()
257258 s .db .User (2 )
258259
259260 test .WithUser (s .ctx , 2 )
260- s .withJSONBody ( `{"id":8,"durationSeconds": 900}` )
261+ s .withElevateRequest ( 8 , 900 )
261262
262263 s .a .ElevateClient (s .ctx )
263264
@@ -271,7 +272,7 @@ func (s *ClientSuite) Test_ElevateClient_expectBadRequestOnMissingID() {
271272 s .db .User (5 )
272273
273274 test .WithUser (s .ctx , 5 )
274- s .withJSONBody (`{"durationSeconds":900}` )
275+ s .withElevateBody (`{"durationSeconds":900}` )
275276
276277 s .a .ElevateClient (s .ctx )
277278
@@ -282,7 +283,8 @@ func (s *ClientSuite) Test_ElevateClient_expectBadRequestOnMissingDuration() {
282283 s .db .User (5 ).Client (8 )
283284
284285 test .WithUser (s .ctx , 5 )
285- s .withJSONBody (`{"id":8}` )
286+ s .ctx .AddParam ("id" , "8" )
287+ s .withElevateBody (`{}` )
286288
287289 s .a .ElevateClient (s .ctx )
288290
@@ -297,8 +299,13 @@ func (s *ClientSuite) withFormData(formData string) {
297299 s .ctx .Request .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
298300}
299301
300- func (s * ClientSuite ) withJSONBody (body string ) {
301- s .ctx .Request = httptest .NewRequest ("POST" , "/client:elevate" , strings .NewReader (body ))
302+ func (s * ClientSuite ) withElevateRequest (id uint , durationSeconds int ) {
303+ s .ctx .AddParam ("id" , fmt .Sprintf ("%d" , id ))
304+ s .withElevateBody (fmt .Sprintf (`{"durationSeconds":%d}` , durationSeconds ))
305+ }
306+
307+ func (s * ClientSuite ) withElevateBody (body string ) {
308+ s .ctx .Request = httptest .NewRequest ("POST" , "/client/ignored/elevate" , strings .NewReader (body ))
302309 s .ctx .Request .Header .Set ("Content-Type" , "application/json" )
303310}
304311
0 commit comments