Bug 27797: (QA follow-up) Additional tests and operator change
authorNick Clemens <nick@bywatersolutions.com>
Thu, 4 Mar 2021 19:50:22 +0000 (19:50 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 4 May 2021 12:22:04 +0000 (14:22 +0200)
I added a few tests to cover additional cases and found the operator precedence
was failing, switched 'and' to '&&'

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/REST/V1/Holds.pm
t/db_dependent/api/v1/holds.t

index 01bbf97..d4530e7 100644 (file)
@@ -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(
index 1297a5a..774508d 100755 (executable)
@@ -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);