Bug 23517: Add a spec for PUT /holds/{hold_id}/priority
authorTomas Cohen Arazi <tomascohen@theke.io>
Tue, 3 Sep 2019 19:39:08 +0000 (16:39 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Mon, 23 Sep 2019 10:51:58 +0000 (11:51 +0100)
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>

api/v1/swagger/paths.json
api/v1/swagger/paths/holds.json
t/db_dependent/api/v1/holds.t

index 453a37a..0264c0f 100644 (file)
@@ -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"
   },
index 14d29b3..2bb0ed0 100644 (file)
       }
     }
   },
+  "/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",
index 1374a7b..4208eb6 100644 (file)
@@ -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) = @_;