From 5da73b604f1458a4442f73e967659454804a102c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 3 Nov 2021 10:44:14 +0100 Subject: [PATCH] Bug 24850: Fix api/v1/holds.t Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- Koha/REST/V1/Holds.pm | 12 +++++++----- t/db_dependent/api/v1/holds.t | 20 ++++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 7541a5c653..256cb40259 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -185,7 +185,7 @@ sub add { # AddReserve expects date to be in syspref format if ($expiration_date) { - $expiration_date = output_pref( dt_from_string( $expiration_date, 'rfc3339' ) ); + $expiration_date = output_pref( { dt => dt_from_string($expiration_date, 'iso'), dateformat => 'iso', dateonly => 1 } ); } my $hold_id = C4::Reserves::AddReserve( @@ -286,7 +286,9 @@ sub edit { reserve_id => $hold_id, branchcode => $pickup_library_id, rank => $priority, - suspend_until => $suspended_until ? output_pref(dt_from_string($suspended_until, 'rfc3339')) : '', + suspend_until => $suspended_until + ? output_pref({ dt => dt_from_string($suspended_until, 'iso'), dateformat => 'iso', dateonly => 1 }) + : '', itemnumber => $hold->itemnumber }; @@ -351,15 +353,15 @@ sub suspend { } return try { - my $date = ($end_date) ? dt_from_string( $end_date, 'rfc3339' ) : undef; + my $date = ($end_date) ? dt_from_string( $end_date, 'iso' ) : undef; $hold->suspend_hold($date); $hold->discard_changes; $c->res->headers->location( $c->req->url->to_string ); my $suspend_end_date; if ($hold->suspend_until) { $suspend_end_date = output_pref({ - dt => dt_from_string( $hold->suspend_until ), - dateformat => 'rfc3339', + dt => dt_from_string( $hold->suspend_until, 'iso' ), + dateformat => 'iso', dateonly => 1 } ); diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index ac18877272..22e9f3e5c6 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -159,11 +159,11 @@ my $post_data = { biblio_id => $biblio_1->biblionumber, item_id => $item_1->itemnumber, pickup_library_id => $branchcode, - expiration_date => output_pref( { dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 } ), + expiration_date => output_pref( { dt => $expiration_date, dateformat => 'iso', dateonly => 1 } ), }; my $patch_data = { priority => 2, - suspended_until => output_pref( { dt => $suspended_until, dateformat => 'rfc3339' } ), + suspended_until => output_pref( { dt => $suspended_until, dateformat => 'iso', dateonly => 1 } ), }; subtest "Test endpoints without authentication" => sub { @@ -254,7 +254,7 @@ subtest "Test endpoints with permission" => sub { $t->get_ok( "//$userid_1:$password@/api/v1/holds?patron_id=" . $patron_1->borrowernumber ) ->status_is(200) ->json_is('/0/hold_id', $reserve_id) - ->json_is('/0/expiration_date', output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 })) + ->json_is('/0/expiration_date', output_pref({ dt => $expiration_date, dateformat => 'iso', dateonly => 1 })) ->json_is('/0/pickup_library_id', $branchcode); $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) @@ -329,8 +329,8 @@ subtest 'test AllowHoldDateInFuture' => sub { biblio_id => $biblio_1->biblionumber, item_id => $item_1->itemnumber, pickup_library_id => $branchcode, - expiration_date => output_pref( { dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 } ), - hold_date => output_pref( { dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 } ), + expiration_date => output_pref( { dt => $expiration_date, dateformat => 'iso', dateonly => 1 } ), + hold_date => output_pref( { dt => $future_hold_date, dateformat => 'iso', dateonly => 1 } ), }; t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); @@ -349,7 +349,7 @@ subtest 'test AllowHoldDateInFuture' => sub { $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) ->status_is(201) - ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 })); + ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'iso', dateonly => 1 })); }; $schema->storage->txn_rollback; @@ -486,7 +486,7 @@ subtest 'suspend and resume tests' => sub { my $end_date = output_pref({ dt => dt_from_string( undef ), - dateformat => 'rfc3339', + dateformat => 'iso', dateonly => 1 }); @@ -499,7 +499,7 @@ subtest 'suspend and resume tests' => sub { '/end_date', output_pref({ dt => dt_from_string( $hold->suspend_until ), - dateformat => 'rfc3339', + dateformat => 'iso', dateonly => 1 }), 'Hold suspension has correct end date' @@ -516,11 +516,11 @@ subtest 'suspend and resume tests' => sub { . $hold->id . "/suspension" => json => { end_date => - output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) + output_pref( { dt => $date, dateformat => 'iso', dateonly => 1 } ) } )->status_is( 201, 'Hold suspension created' ) ->json_is( '/end_date', - output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) ) + output_pref( { dt => $date, dateformat => 'iso', 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" ) -- 2.39.5