Browse Source

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 <tomascohen@theke.io>
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
remotes/origin/19.11.x
Tomas Cohen Arazi 3 years ago
committed by Martin Renvoize
parent
commit
c9e3060f31
Signed by: martin.renvoize GPG Key ID: 422B469130441A0F
  1. 3
      api/v1/swagger/paths.json
  2. 76
      api/v1/swagger/paths/holds.json
  3. 88
      t/db_dependent/api/v1/holds.t

3
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"
},

76
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",

88
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) = @_;

Loading…
Cancel
Save