From 6d8600b14c15292900c086f2db4b255910e9ae6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johanna=20R=C3=A4is=C3=A4?= Date: Mon, 3 Mar 2025 10:13:50 +0200 Subject: [PATCH] Bug 38253: (follow-up) add boolean value to body parameter This patch adds the boolean value to the body parameter to change the status of the lowest priority hold. --- Koha/REST/V1/Holds.pm | 4 +++- api/v1/swagger/paths/holds.yaml | 4 ++-- t/db_dependent/api/v1/holds.t | 15 +++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 7f8764e6cb..8ac65f6b85 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -552,7 +552,9 @@ sub lowest_priority { unless $hold; return try { - C4::Reserves::ToggleLowestPriority($hold_id); + my $lowestPriority = $c->req->json; + $hold->set( { lowestPriority => $lowestPriority } )->store; + C4::Reserves::_FixPriority( { reserve_id => $hold_id, rank => '999999' } ); $hold->discard_changes; # refresh return $c->render( status => 200, openapi => $hold_id ); } catch { diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index a6aff1b75c..01978a662a 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -773,9 +773,9 @@ - name: body in: body description: An integer representing the new priority to be set for the hold - required: false + required: true schema: - type: integer + type: boolean produces: - application/json responses: diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index a07374d751..4f6c2de3af 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -1500,7 +1500,7 @@ subtest 'delete() tests' => sub { subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { - plan tests => 5; + plan tests => 8; $schema->storage->txn_begin; @@ -1541,11 +1541,18 @@ subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { ) ); - $t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/lowest_priority" )->status_is(404); + $t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/lowest_priority" => json => Mojo::JSON->true ) + ->status_is(404); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/lowest_priority" => json => Mojo::JSON->true ) + ->status_is(200); - $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/lowest_priority" )->status_is(200); + is( $hold->discard_changes->lowestPriority, 1, 'The lowest priority is set' ); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/lowest_priority" => json => Mojo::JSON->false ) + ->status_is(200); - is( $hold->discard_changes->lowestPriority, 1, 'Priority set to lowest' ); + is( $hold->discard_changes->lowestPriority, 0, 'The lowest priority removed' ); $schema->storage->txn_rollback; }; -- 2.34.1