From 51252d6c3452a46d0a53f919a236218193538c5d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 May 2021 15:04:17 +0200 Subject: [PATCH] Bug 28254: Add missing tests for PUT and POST --- t/db_dependent/api/v1/holds.t | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 49cd3a7df73..674172e6053 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -358,7 +358,7 @@ $schema->storage->txn_rollback; subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { - plan tests => 16; + plan tests => 18; $schema->storage->txn_begin; @@ -445,6 +445,12 @@ subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { { 'x-koha-override' => 'any' } => json => $post_data ) ->status_is(201); + t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0); + + $t->post_ok( "//$userid:$password@/api/v1/holds" => + { 'x-koha-override' => 'any' } => json => $post_data ) + ->status_is(400); + $schema->storage->txn_rollback; }; @@ -1136,7 +1142,7 @@ subtest 'add() tests' => sub { subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { - plan tests => 20; + plan tests => 28; $schema->storage->txn_begin; @@ -1251,5 +1257,23 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $hold->id + . "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } ) + ->status_is(400) + ->json_is({ error => '[The supplied pickup location is not valid]' }); + + is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'invalid pickup library not used' ); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $hold->id + . "/pickup_location" + => { 'x-koha-override' => 'any' } + => json => { pickup_library_id => $library_3->branchcode } ) + ->status_is(400) + ->json_is({ error => '[The supplied pickup location is not valid]' }); + + is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'invalid pickup library not used, even if x-koha-override is passed' ); + $schema->storage->txn_rollback; }; -- 2.20.1