From 14686972ce6920ec8eb3ce453d6c6bc89914f36c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 28 Feb 2019 10:00:27 -0300 Subject: [PATCH] Bug 22206: (follow-up) Voted RFC changes This patch changes expiration_date for end_date as voted when the RFC was approved. It also adds a test for the Location header being added correctly when suspending a hold (SWAGGER3.4.1) Signed-off-by: Tomas Cohen Arazi Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens (cherry picked from commit 6ebcc255d3def898c491333bc8702c56b09e4537) Signed-off-by: Martin Renvoize --- Koha/REST/V1/Holds.pm | 6 +++--- api/v1/swagger/paths/holds.json | 2 +- t/db_dependent/api/v1/holds.t | 11 ++++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 190a57ef3d..58ddf1f273 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -284,21 +284,21 @@ sub suspend { my $hold_id = $c->validation->param('hold_id'); my $hold = Koha::Holds->find($hold_id); my $body = $c->req->json; - my $exp_date = ($body) ? $body->{expiration_date} : undef; + my $end_date = ($body) ? $body->{end_date} : undef; unless ($hold) { return $c->render( status => 404, openapi => { error => 'Hold not found.' } ); } return try { - my $date = ($exp_date) ? dt_from_string( $exp_date, 'rfc3339' ) : undef; + my $date = ($end_date) ? dt_from_string( $end_date, 'rfc3339' ) : undef; $hold->suspend_hold($date); $hold->discard_changes; $c->res->headers->location( $c->req->url->to_string ); return $c->render( status => 201, openapi => { - expiration_date => output_pref( + end_date => output_pref( { dt => dt_from_string( $hold->suspend_until ), dateformat => 'rfc3339', dateonly => 1 diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index 2dea98c53b..68e03da625 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -402,7 +402,7 @@ "schema": { "type": "object", "properties": { - "expiration_date": { + "end_date": { "description": "Date the hold suspension expires", "type": "string", "format": "date" diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 294d6562dd..8ca3899f37 100644 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -330,7 +330,7 @@ $schema->storage->txn_rollback; subtest 'suspend and resume tests' => sub { - plan tests => 20; + plan tests => 21; $schema->storage->txn_begin; @@ -359,7 +359,7 @@ subtest 'suspend and resume tests' => sub { ok( $hold->is_suspended, 'Hold is suspended' ); $t->json_is( - '/expiration_date', + '/end_date', output_pref( { dt => dt_from_string( $hold->suspend_until ), dateformat => 'rfc3339', @@ -378,12 +378,13 @@ subtest 'suspend and resume tests' => sub { "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" => json => { - expiration_date => + end_date => output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) } )->status_is( 201, 'Hold suspension created' ) - ->json_is( '/expiration_date', - output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) ); + ->json_is( '/end_date', + output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) ) + ->header_is( Location => "/api/v1/holds/" . $hold->id . "/suspension", 'The Location header is set' ); $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" ) ->status_is( 204, "Correct status when deleting a resource" ) -- 2.39.5