From 292901f4a384ab7c884771d098a2ad3bd2a1a1c1 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Tue, 24 Mar 2015 11:30:00 +0100 Subject: [PATCH] Bug 13903: (QA followup) change routes to /holds GET /holds?borrowernumber=X (list) POST /holds (create) PUT /holds/{reserve_id} (update) DELETE /holds/{reserve_id} (delete) Unit tests in t/db_dependent/api/v1/holds.t Signed-off-by: Jesse Weaver --- Koha/REST/V1/{Reserve.pm => Hold.pm} | 2 +- api/v1/definitions/{reserve.json => hold.json} | 14 +-- api/v1/definitions/holds.json | 4 + api/v1/definitions/index.json | 4 +- api/v1/definitions/reserves.json | 4 - api/v1/swagger.json | 50 ++++---- t/db_dependent/api/v1/reserves.t | 154 ------------------------- 7 files changed, 39 insertions(+), 193 deletions(-) rename Koha/REST/V1/{Reserve.pm => Hold.pm} (99%) rename api/v1/definitions/{reserve.json => hold.json} (78%) create mode 100644 api/v1/definitions/holds.json delete mode 100644 api/v1/definitions/reserves.json delete mode 100644 t/db_dependent/api/v1/reserves.t diff --git a/Koha/REST/V1/Reserve.pm b/Koha/REST/V1/Hold.pm similarity index 99% rename from Koha/REST/V1/Reserve.pm rename to Koha/REST/V1/Hold.pm index 69e6e98..208488d 100644 --- a/Koha/REST/V1/Reserve.pm +++ b/Koha/REST/V1/Hold.pm @@ -1,4 +1,4 @@ -package Koha::REST::V1::Reserve; +package Koha::REST::V1::Hold; # This file is part of Koha. # diff --git a/api/v1/definitions/reserve.json b/api/v1/definitions/hold.json similarity index 78% rename from api/v1/definitions/reserve.json rename to api/v1/definitions/hold.json index 74370fe..17bc834 100644 --- a/api/v1/definitions/reserve.json +++ b/api/v1/definitions/hold.json @@ -2,14 +2,14 @@ "type": "object", "properties": { "reserve_id": { - "description": "Internal reserve identifier" + "description": "Internal hold identifier" }, "borrowernumber": { "type": "string", "description": "internally assigned user identifier" }, "reservedate": { - "description": "the date the reserve was placed" + "description": "the date the hold was placed" }, "biblionumber": { "type": "string", @@ -26,19 +26,19 @@ "description": "currently unused" }, "cancellationdate": { - "description": "the date the reserve was cancelled" + "description": "the date the hold was cancelled" }, "reservenotes": { - "description": "notes related to this reserve" + "description": "notes related to this hold" }, "priority": { "description": "where in the queue the patron sits" }, "found": { - "description": "a one letter code defining what the status of the reserve is after it has been confirmed" + "description": "a one letter code defining what the status of the hold is after it has been confirmed" }, "timestamp": { - "description": "date and time the reserve was last updated" + "description": "date and time the hold was last updated" }, "itemnumber": { "type": ["string", "null"], @@ -48,7 +48,7 @@ "description": "the date the item was marked as waiting for the patron at the library" }, "expirationdate": { - "description": "the date the reserve expires" + "description": "the date the hold expires" }, "lowestPriority": { "description": "" diff --git a/api/v1/definitions/holds.json b/api/v1/definitions/holds.json new file mode 100644 index 0000000..6d64441 --- /dev/null +++ b/api/v1/definitions/holds.json @@ -0,0 +1,4 @@ +{ + "type": "array", + "items": { "$ref": "hold.json" } +} diff --git a/api/v1/definitions/index.json b/api/v1/definitions/index.json index 4e17693..3f69544 100644 --- a/api/v1/definitions/index.json +++ b/api/v1/definitions/index.json @@ -1,6 +1,6 @@ { "patron": { "$ref": "patron.json" }, - "reserves": { "$ref": "reserves.json" }, - "reserve": { "$ref": "reserve.json" }, + "holds": { "$ref": "holds.json" }, + "hold": { "$ref": "hold.json" }, "error": { "$ref": "error.json" } } diff --git a/api/v1/definitions/reserves.json b/api/v1/definitions/reserves.json deleted file mode 100644 index 431c444..0000000 --- a/api/v1/definitions/reserves.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "array", - "items": { "$ref": "reserve.json" } -} diff --git a/api/v1/swagger.json b/api/v1/swagger.json index b5c6d0a..1488aba 100644 --- a/api/v1/swagger.json +++ b/api/v1/swagger.json @@ -74,10 +74,10 @@ } } }, - "/reserves": { + "/holds": { "get": { - "operationId": "listReserves", - "tags": ["borrowers", "reserves"], + "operationId": "listHolds", + "tags": ["borrowers", "holds"], "parameters": [ { "name": "borrowernumber", @@ -90,8 +90,8 @@ "produces": ["application/json"], "responses": { "200": { - "description": "A list of reserves", - "schema": { "$ref": "#/definitions/reserves" } + "description": "A list of holds", + "schema": { "$ref": "#/definitions/holds" } }, "404": { "description": "Borrower not found", @@ -100,13 +100,13 @@ } }, "post": { - "operationId": "addReserve", - "tags": ["borrowers", "reserves"], + "operationId": "addHold", + "tags": ["borrowers", "holds"], "parameters": [ { "name": "body", "in": "body", - "description": "A JSON object containing informations about the new reserve", + "description": "A JSON object containing informations about the new hold", "required": true, "schema": { "type": "object", @@ -128,7 +128,7 @@ "type": "string" }, "expirationdate": { - "description": "Reserve end date", + "description": "Hold end date", "type": "string", "format": "date" } @@ -140,15 +140,15 @@ "produces": ["application/json"], "responses": { "201": { - "description": "Created reserve", - "schema": { "$ref": "#/definitions/reserve" } + "description": "Created hold", + "schema": { "$ref": "#/definitions/hold" } }, "400": { "description": "Missing or wrong parameters", "schema": { "$ref": "#/definitions/error" } }, "403": { - "description": "Reserve not allowed", + "description": "Hold not allowed", "schema": { "$ref": "#/definitions/error" } }, "404": { @@ -162,12 +162,12 @@ } } }, - "/reserves/{reserve_id}": { + "/holds/{reserve_id}": { "put": { - "operationId": "editReserve", - "tags": ["reserves"], + "operationId": "editHold", + "tags": ["holds"], "parameters": [ - { "$ref": "#/parameters/reserveIdPathParam" }, + { "$ref": "#/parameters/holdIdPathParam" }, { "name": "body", "in": "body", @@ -198,24 +198,24 @@ "produces": ["application/json"], "responses": { "200": { - "description": "Updated reserve", - "schema": { "$ref": "#/definitions/reserve" } + "description": "Updated hold", + "schema": { "$ref": "#/definitions/hold" } }, "400": { "description": "Missing or wrong parameters", "schema": { "$ref": "#/definitions/error" } }, "404": { - "description": "Reserve not found", + "description": "Hold not found", "schema": { "$ref": "#/definitions/error" } } } }, "delete": { - "operationId": "deleteReserve", - "tags": ["reserves"], + "operationId": "deleteHold", + "tags": ["holds"], "parameters": [ - { "$ref": "#/parameters/reserveIdPathParam" } + { "$ref": "#/parameters/holdIdPathParam" } ], "produces": ["application/json"], "responses": { @@ -226,7 +226,7 @@ } }, "404": { - "description": "Reserve not found", + "description": "Hold not found", "schema": { "$ref": "#/definitions/error" } } } @@ -244,10 +244,10 @@ "required": true, "type": "integer" }, - "reserveIdPathParam": { + "holdIdPathParam": { "name": "reserve_id", "in": "path", - "description": "Internal reserve identifier", + "description": "Internal hold identifier", "required": true, "type": "integer" } diff --git a/t/db_dependent/api/v1/reserves.t b/t/db_dependent/api/v1/reserves.t deleted file mode 100644 index eeccbfd..0000000 --- a/t/db_dependent/api/v1/reserves.t +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env perl - -# This file is part of Koha. -# -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3 of the License, or (at your option) any later -# version. -# -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -use Modern::Perl; - -use Test::More tests => 30; -use Test::Mojo; - -use DateTime; - -use C4::Context; -use C4::Biblio; -use C4::Items; -use C4::Reserves; - -use Koha::Database; -use Koha::Patron; - -my $dbh = C4::Context->dbh; -$dbh->{AutoCommit} = 0; -$dbh->{RaiseError} = 1; - -my $t = Test::Mojo->new('Koha::REST::V1'); - -my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); -my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); - -my $borrower = Koha::Patron->new; -$borrower->categorycode( $categorycode ); -$borrower->branchcode( $branchcode ); -$borrower->surname("Test Surname"); -$borrower->store; -my $borrowernumber = $borrower->borrowernumber; - -my $borrower2 = Koha::Patron->new; -$borrower2->categorycode( $categorycode ); -$borrower2->branchcode( $branchcode ); -$borrower2->surname("Test Surname 2"); -$borrower2->store; -my $borrowernumber2 = $borrower2->borrowernumber; - -my $biblionumber = create_biblio('RESTful Web APIs'); -my $itemnumber = create_item($biblionumber, 'TEST000001'); - -my $reserve_id = C4::Reserves::AddReserve($branchcode, $borrowernumber, - $biblionumber, undef, 1, undef, undef, undef, '', $itemnumber); - -# Add another reserve to be able to change first reserve's rank -C4::Reserves::AddReserve($branchcode, $borrowernumber2, - $biblionumber, undef, 2, undef, undef, undef, '', $itemnumber); - -my $suspend_until = DateTime->now->add(days => 10)->ymd; -my $put_data = { - priority => 2, - suspend_until => $suspend_until, -}; -$t->put_ok("/api/v1/reserves/$reserve_id" => json => $put_data) - ->status_is(200) - ->json_is('/reserve_id', $reserve_id) - ->json_is('/suspend_until', $suspend_until . ' 00:00:00') - ->json_is('/priority', 2); - -$t->delete_ok("/api/v1/reserves/$reserve_id") - ->status_is(200); - -$t->put_ok("/api/v1/reserves/$reserve_id" => json => $put_data) - ->status_is(404) - ->json_has('/error'); - -$t->delete_ok("/api/v1/reserves/$reserve_id") - ->status_is(404) - ->json_has('/error'); - - -$t->get_ok("/api/v1/reserves?borrowernumber=$borrowernumber") - ->status_is(200) - ->json_is([]); - -my $inexisting_borrowernumber = $borrowernumber2 + 1; -$t->get_ok("/api/v1/reserves?borrowernumber=$inexisting_borrowernumber") - ->status_is(404) - ->json_has('/error'); - -$dbh->do('DELETE FROM issuingrules'); -$dbh->do(q{ - INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) - VALUES (?, ?, ?, ?) -}, {}, '*', '*', '*', 1); - -my $expirationdate = DateTime->now->add(days => 10)->ymd; -my $post_data = { - borrowernumber => int($borrowernumber), - biblionumber => int($biblionumber), - itemnumber => int($itemnumber), - branchcode => $branchcode, - expirationdate => $expirationdate, -}; -$t->post_ok("/api/v1/reserves" => json => $post_data) - ->status_is(201) - ->json_has('/reserve_id'); - -$reserve_id = $t->tx->res->json->{reserve_id}; - -$t->get_ok("/api/v1/reserves?borrowernumber=$borrowernumber") - ->status_is(200) - ->json_is('/0/reserve_id', $reserve_id) - ->json_is('/0/expirationdate', $expirationdate) - ->json_is('/0/branchcode', $branchcode); - -$t->post_ok("/api/v1/reserves" => json => $post_data) - ->status_is(403) - ->json_like('/error', qr/tooManyReserves/); - - -$dbh->rollback; - -sub create_biblio { - my ($title) = @_; - - my $record = new MARC::Record; - $record->append_fields( - new MARC::Field('200', ' ', ' ', a => $title), - ); - - my ($biblionumber) = C4::Biblio::AddBiblio($record, ''); - - return $biblionumber; -} - -sub create_item { - my ($biblionumber, $barcode) = @_; - - my $item = { - barcode => $barcode, - }; - - my $itemnumber = C4::Items::AddItem($item, $biblionumber); - - return $itemnumber; -} -- 2.8.0.rc3