@@ -292,16 +292,15 @@ defmodule Projecthub.HttpApi.Test do
292
292
p1 = create ( "project1" , p1_id )
293
293
p2 = create ( "project2" , p2_id )
294
294
p3 = create ( "project3" , p3_id )
295
+ page_size = Application . get_env ( :projecthub , :projects_page_size )
295
296
296
297
FunRegistry . set! ( FakeServices.RbacService , :list_accessible_projects , fn _ , _ ->
297
298
InternalApi.RBAC.ListAccessibleProjectsResponse . new ( project_ids: [ p1_id , p2_id , p3_id ] )
298
299
end )
299
300
300
301
FunRegistry . set! ( FakeServices.ProjectService , :list , fn req , _ ->
301
302
alias InternalApi.Projecthub , as: PH
302
- # Simulate pagination
303
303
page = req . pagination . page
304
- page_size = req . pagination . page_size
305
304
all_projects = [ p1 , p2 , p3 ]
306
305
projects = Enum . slice ( all_projects , ( page - 1 ) * page_size , page_size )
307
306
@@ -327,30 +326,50 @@ defmodule Projecthub.HttpApi.Test do
327
326
test "returns correct pagination headers for /projects" do
328
327
{ :ok , response } =
329
328
HTTPoison . get (
330
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=1&page_size=2 " ,
329
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=1" ,
331
330
@ headers
332
331
)
333
332
334
333
assert response . status_code == 200
335
334
assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-page" and v == "1" end )
336
- assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-page-size" and v == "2" end )
337
- assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-total-count" and v == "3" end )
338
335
assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-has-more" and v == "true" end )
339
336
projects = Poison . decode! ( response . body )
340
337
assert length ( projects ) == 2
338
+
339
+ { :ok , response2 } =
340
+ HTTPoison . get (
341
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=2" ,
342
+ @ headers
343
+ )
344
+
345
+ assert response2 . status_code == 200
346
+ assert response2 . headers |> Enum . any? ( fn { k , v } -> k == "x-page" and v == "2" end )
347
+ assert response2 . headers |> Enum . any? ( fn { k , v } -> k == "x-has-more" and v == "false" end )
348
+ projects2 = Poison . decode! ( response2 . body )
349
+ assert length ( projects2 ) == 1
350
+
351
+ { :ok , response3 } =
352
+ HTTPoison . get (
353
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=3" ,
354
+ @ headers
355
+ )
356
+
357
+ assert response3 . status_code == 200
358
+ assert response3 . headers |> Enum . any? ( fn { k , v } -> k == "x-page" and v == "3" end )
359
+ assert response3 . headers |> Enum . any? ( fn { k , v } -> k == "x-has-more" and v == "false" end )
360
+ projects3 = Poison . decode! ( response3 . body )
361
+ assert Enum . empty? ( projects3 )
341
362
end
342
363
343
364
test "returns correct pagination headers for /projects when there are no more projects" do
344
365
{ :ok , response } =
345
366
HTTPoison . get (
346
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=2&page_size=2 " ,
367
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=2" ,
347
368
@ headers
348
369
)
349
370
350
371
assert response . status_code == 200
351
372
assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-page" and v == "2" end )
352
- assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-page-size" and v == "2" end )
353
- assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-total-count" and v == "3" end )
354
373
assert response . headers |> Enum . any? ( fn { k , v } -> k == "x-has-more" and v == "false" end )
355
374
projects = Poison . decode! ( response . body )
356
375
assert length ( projects ) == 1
@@ -371,7 +390,7 @@ defmodule Projecthub.HttpApi.Test do
371
390
372
391
{ :ok , response } =
373
392
HTTPoison . get (
374
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=10&page_size=2 " ,
393
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=10" ,
375
394
@ headers
376
395
)
377
396
@@ -401,7 +420,7 @@ defmodule Projecthub.HttpApi.Test do
401
420
402
421
{ :ok , response } =
403
422
HTTPoison . get (
404
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=foo&page_size=bar " ,
423
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=foo" ,
405
424
@ headers
406
425
)
407
426
@@ -411,29 +430,18 @@ defmodule Projecthub.HttpApi.Test do
411
430
test "returns 400 on negative page" do
412
431
{ :ok , response } =
413
432
HTTPoison . get (
414
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=-1&page_size=2 " ,
433
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=-1" ,
415
434
@ headers
416
435
)
417
436
418
437
assert response . status_code == 400
419
438
assert Poison . decode! ( response . body ) [ "message" ] =~ "page must be at least 1"
420
439
end
421
440
422
- test "returns 400 on zero page_size" do
423
- { :ok , response } =
424
- HTTPoison . get (
425
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=1&page_size=0" ,
426
- @ headers
427
- )
428
-
429
- assert response . status_code == 400
430
- assert Poison . decode! ( response . body ) [ "message" ] =~ "page_size must be at least 1"
431
- end
432
-
433
441
test "returns 400 on too large page" do
434
442
{ :ok , response } =
435
443
HTTPoison . get (
436
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=9999&page_size=2 " ,
444
+ "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=9999" ,
437
445
@ headers
438
446
)
439
447
@@ -443,28 +451,6 @@ defmodule Projecthub.HttpApi.Test do
443
451
assert Poison . decode! ( response . body ) [ "message" ] =~ "page must be at most"
444
452
end
445
453
end
446
-
447
- test "returns 400 on too large page_size" do
448
- { :ok , response } =
449
- HTTPoison . get (
450
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=1&page_size=9999" ,
451
- @ headers
452
- )
453
-
454
- assert response . status_code == 400
455
- assert Poison . decode! ( response . body ) [ "message" ] =~ "page_size must be at most"
456
- end
457
-
458
- test "returns 400 on non-numeric page_size" do
459
- { :ok , response } =
460
- HTTPoison . get (
461
- "http://localhost:#{ @ port } /api/#{ @ version } /projects?page=1&page_size=abc" ,
462
- @ headers
463
- )
464
-
465
- assert response . status_code == 400
466
- assert Poison . decode! ( response . body ) [ "message" ] =~ "page_size must be a number"
467
- end
468
454
end
469
455
470
456
describe "GET /api/<version>/projects/:name with authorized user" do
@@ -1828,7 +1814,7 @@ defmodule Projecthub.HttpApi.Test do
1828
1814
1829
1815
def create ( name , id ) do
1830
1816
alias InternalApi.Projecthub.Project
1831
- alias InternalApi.Projecthub.Project.Spec . { Repository , Visibility , PermissionType }
1817
+ alias InternalApi.Projecthub.Project.Spec . { PermissionType , Repository , Visibility }
1832
1818
1833
1819
Project . new (
1834
1820
metadata: Project.Metadata . new ( name: name , id: id ) ,
0 commit comments