From 01209c228d196925f00124ce71b206321d7f4132 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 4 Mar 2021 19:50:22 +0000 Subject: [PATCH] Bug 27797: (QA follow-up) Additional tests and operator change I added a few tests to cover additional cases and found the operator precedence was failing, switched 'and' to '&&' Signed-off-by: Nick Clemens Signed-off-by: Jonathan Druart --- Koha/REST/V1/Holds.pm | 2 +- t/db_dependent/api/v1/holds.t | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 01bbf976a7..d4530e7dd0 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -172,7 +172,7 @@ sub add { } my $overrides = $c->stash('koha.overrides'); - my $can_override = $overrides->{any} and C4::Context->preference('AllowHoldPolicyOverride'); + my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride'); unless ( $can_override || $can_place_hold->{status} eq 'OK' ) { return $c->render( diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 1297a5a149..774508d419 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 => 8; + plan tests => 12; $schema->storage->txn_begin; @@ -407,6 +407,11 @@ subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { ->status_is(403) ->json_is( '/error' => "Hold cannot be placed. Reason: ageRestricted" ); + # x-koha-override doesn't override if AllowHoldPolicyOverride not set + $t->post_ok( "//$userid:$password@/api/v1/holds" => + { 'x-koha-override' => 'any' } => json => $post_data ) + ->status_is(403); + t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); $can_item_be_reserved_result = { status => 'pickupNotInHoldGroup' }; @@ -416,8 +421,14 @@ subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub { ->json_is( '/error' => "Hold cannot be placed. Reason: pickupNotInHoldGroup" ); + # x-koha-override overrides the status + $t->post_ok( "//$userid:$password@/api/v1/holds" => + { 'x-koha-override' => 'any' } => json => $post_data ) + ->status_is(201); + $can_item_be_reserved_result = { status => 'OK' }; + # x-koha-override works when status not need override $t->post_ok( "//$userid:$password@/api/v1/holds" => { 'x-koha-override' => 'any' } => json => $post_data ) ->status_is(201); -- 2.39.5