From edba6dfb7abcf64ec19f5570bea15ddf49e48a6c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 3 Sep 2019 16:39:08 -0300 Subject: [PATCH] Bug 23517: Add a spec for PUT /holds/{hold_id}/priority This patch adds the OpenAPI spec for the endpoint, and tests for the desired behaviour. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Owen Leonard Signed-off-by: Josef Moravec --- api/v1/swagger/paths.json | 3 ++ api/v1/swagger/paths/holds.json | 76 +++++++++++++++++++++++++++++++++++ t/db_dependent/api/v1/holds.t | 88 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 166 insertions(+), 1 deletion(-) diff --git a/api/v1/swagger/paths.json b/api/v1/swagger/paths.json index 946de0a6a4..14b36cd1a1 100644 --- a/api/v1/swagger/paths.json +++ b/api/v1/swagger/paths.json @@ -35,6 +35,9 @@ "/holds/{hold_id}": { "$ref": "paths/holds.json#/~1holds~1{hold_id}" }, + "/holds/{hold_id}/priority": { + "$ref": "paths/holds.json#/~1holds~1{hold_id}~1priority" + }, "/holds/{hold_id}/suspension": { "$ref": "paths/holds.json#/~1holds~1{hold_id}~1suspension" }, diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index 14d29b352d..2bb0ed0179 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -399,6 +399,82 @@ } } }, + "/holds/{hold_id}/priority": { + "put": { + "x-mojo-to": "Holds#update_priority", + "operationId": "updateHoldPriority", + "tags": [ + "biblios", + "holds" + ], + "parameters": [ + { + "$ref": "../parameters.json#/hold_id_pp" + }, + { + "name": "body", + "in": "body", + "description": "An integer representing the new priority to be set for the hold", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "The new priority value for the hold", + "schema": { + "type": "integer" + } + }, + "401": { + "description": "Authentication required", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "403": { + "description": "Access forbidden", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "404": { + "description": "Biblio not found", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "409": { + "description": "Unable to perform action on biblio", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "500": { + "description": "Internal error", + "schema": { + "$ref": "../definitions.json#/error" + } + }, + "503": { + "description": "Under maintenance", + "schema": { + "$ref": "../definitions.json#/error" + } + } + }, + "x-koha-authorization": { + "permissions": { + "reserveforothers": "modify_holds_priority" + } + } + } + }, "/holds/{hold_id}/suspension": { "post": { "x-mojo-to": "Holds#suspend", diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 1374a7b159..4208eb6225 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 6; use Test::Mojo; use t::lib::TestBuilder; use t::lib::Mocks; @@ -405,6 +405,92 @@ subtest 'suspend and resume tests' => sub { $schema->storage->txn_rollback; }; +subtest 'PUT /holds/{hold_id}/priority tests' => sub { + + plan tests => 8; + + $schema->storage->txn_begin; + + my $password = 'AbcdEFG123'; + + my $patron_np = $builder->build_object( + { class => 'Koha::Patrons', value => { flags => 0 } } ); + $patron_np->set_password( { password => $password, skip_validation => 1 } ); + my $userid_np = $patron_np->userid; + + my $patron = $builder->build_object( + { class => 'Koha::Patrons', value => { flags => 0 } } ); + $patron->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $patron->userid; + $builder->build( + { + source => 'UserPermission', + value => { + borrowernumber => $patron->borrowernumber, + module_bit => 6, + code => 'modify_holds_priority', + }, + } + ); + + # Disable logging + t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); + t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); + + my $biblio = $builder->build_sample_biblio; + + my $hold_1 = $builder->build_object( + { + class => 'Koha::Holds', + value => { + suspend => 0, + suspend_until => undef, + waitingdate => undef, + biblionumber => $biblio->biblionumber, + priority => 1 + } + } + ); + my $hold_2 = $builder->build_object( + { + class => 'Koha::Holds', + value => { + suspend => 0, + suspend_until => undef, + waitingdate => undef, + biblionumber => $biblio->biblionumber, + priority => 2 + } + } + ); + my $hold_3 = $builder->build_object( + { + class => 'Koha::Holds', + value => { + suspend => 0, + suspend_until => undef, + waitingdate => undef, + biblionumber => $biblio->biblionumber, + priority => 3 + } + } + ); + + $t->put_ok( "//$userid_np:$password@/api/v1/holds/" + . $hold_3->id + . "/priority" => json => 1 )->status_is(403); + + $t->put_ok( "//$userid:$password@/api/v1/holds/" + . $hold_3->id + . "/priority" => json => 1 )->status_is(200)->json_is(1); + + is( $hold_1->discard_changes->priority, 2, 'Priority adjusted correctly' ); + is( $hold_2->discard_changes->priority, 3, 'Priority adjusted correctly' ); + is( $hold_3->discard_changes->priority, 1, 'Priority adjusted correctly' ); + + $schema->storage->txn_rollback; +}; + sub create_biblio { my ($title) = @_; -- 2.11.0