From 47ad7afccaf1ca0ae7b8dbfad9998aaac6d9a938 Mon Sep 17 00:00:00 2001 From: Josef Moravec Date: Mon, 25 Feb 2019 22:17:01 +0000 Subject: [PATCH] Bug 13895: (follow-up) Fix POST response Test plan: prove t/db_dependent/api/v1/chcekouts.t Signed-off-by: Michal Denar Signed-off-by: Nick Clemens --- Koha/REST/V1/Checkout.pm | 3 ++- api/v1/swagger/paths/checkouts.json | 2 +- t/db_dependent/api/v1/checkouts.t | 13 ++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Koha/REST/V1/Checkout.pm b/Koha/REST/V1/Checkout.pm index a454fc4514..3dba36c316 100644 --- a/Koha/REST/V1/Checkout.pm +++ b/Koha/REST/V1/Checkout.pm @@ -118,8 +118,9 @@ sub renew { AddRenewal($borrowernumber, $itemnumber, $checkout->branchcode); $checkout = Koha::Checkouts->find($checkout_id); + $c->res->headers->location( $c->req->url->to_string ); return $c->render( - status => 200, + status => 201, openapi => _to_api( $checkout->TO_JSON ) ); } diff --git a/api/v1/swagger/paths/checkouts.json b/api/v1/swagger/paths/checkouts.json index 6324d75bce..134aee55ad 100644 --- a/api/v1/swagger/paths/checkouts.json +++ b/api/v1/swagger/paths/checkouts.json @@ -73,7 +73,7 @@ }], "produces": ["application/json"], "responses": { - "200": { + "201": { "description": "Updated borrower's checkout", "schema": { "$ref": "../definitions.json#/checkout" } }, diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index a6f340b31d..b3c31cc8c9 100644 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 51; +use Test::More tests => 53; use Test::MockModule; use Test::Mojo; use t::lib::Mocks; @@ -137,8 +137,9 @@ $dbh->do(q{ my $expected_datedue = DateTime->now->add(days => 14)->set(hour => 23, minute => 59, second => 0); $t->post_ok ( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/renewal" ) - ->status_is(200) - ->json_is('/due_date' => output_pref( { dateformat => "rfc3339", dt => $expected_datedue }) ); + ->status_is(201) + ->json_is('/due_date' => output_pref( { dateformat => "rfc3339", dt => $expected_datedue }) ) + ->header_is(Location => "/api/v1/checkouts/" . $issue1->issue_id . "/renewal"); $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->issue_id . "/renewal" ) ->status_is(403) @@ -147,8 +148,10 @@ $t->post_ok( "//$unauth_userid:$unauth_password@/api/v1/checkouts/" . $issue3->i }); $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/renewal" ) - ->status_is(200) - ->json_is('/due_date' => output_pref({ dateformat => "rfc3339", dt => $expected_datedue}) ); + ->status_is(201) + ->json_is('/due_date' => output_pref({ dateformat => "rfc3339", dt => $expected_datedue}) ) + ->header_is(Location => "/api/v1/checkouts/" . $issue2->issue_id . "/renewal"); + $t->post_ok( "//$userid:$password@/api/v1/checkouts/" . $issue1->issue_id . "/renewal" ) ->status_is(403) -- 2.39.5