From 855cda85188777fd9cc502d624970eb0b0ff2c78 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 18 Feb 2022 15:33:42 -0300 Subject: [PATCH] Bug 30133: Regression tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Andrew Fuerste-Henry https://bugs.koha-community.org/show_bug.cgi?id=30113 --- t/db_dependent/api/v1/items.t | 44 ++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t index 4136c28a08..0d4f4c0ea4 100755 --- a/t/db_dependent/api/v1/items.t +++ b/t/db_dependent/api/v1/items.t @@ -144,7 +144,7 @@ subtest 'get() tests' => sub { subtest 'pickup_locations() tests' => sub { - plan tests => 15; + plan tests => 16; $schema->storage->txn_begin; @@ -237,6 +237,48 @@ subtest 'pickup_locations() tests' => sub { . "patron_id=" . $patron->id . "&_order_by=marc_org_code" ) ->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] ); + subtest 'Pagination and AllowHoldPolicyOverride tests' => sub { + + plan tests => 27; + + t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); + + $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->id . "/pickup_locations?" . "patron_id=" . $patron->id . "&_order_by=marc_org_code" . "&_per_page=1" ) + ->json_is( [$library_1_api] ) + ->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) + ->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) + ->header_unlike( 'Link', qr|rel="prev"| ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1).*>\; rel="last"# ); + + $t->get_ok( "//$userid:$password@/api/v1/items/" + . $item->id + . "/pickup_locations?" + . "patron_id=" + . $patron->id + . "&_order_by=marc_org_code" + . "&_per_page=1&_page=3" ) # force the needs_override=1 check + ->json_is( [$library_3_api] ) + ->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) + ->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="prev"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1.*)>\; rel="next"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=4.*|_page=4.*\&_per_page=1).*>\; rel="last"# ); + + t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); + + $t->get_ok( "//$userid:$password@/api/v1/items/" . $item->id . "/pickup_locations?" . "patron_id=" . $patron->id . "&_order_by=marc_org_code" . "&_per_page=1" ) + ->json_is( [$library_1_api] ) + ->header_is( 'X-Total-Count', '2' ) + ->header_is( 'X-Base-Total-Count', '2' ) + ->header_unlike( 'Link', qr|rel="prev"| ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# ) + ->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1).*>\; rel="last"# ); + }; + my $deleted_patron = $builder->build_object({ class => 'Koha::Patrons' }); my $deleted_patron_id = $deleted_patron->id; $deleted_patron->delete; -- 2.30.2