From 98ddc10626fbcaec639b4d2d35d26b5873f5de41 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Wed, 20 Oct 2021 17:02:28 +1300 Subject: [PATCH] Bug 24718: Holds API fixes for datetime --- api/v1/swagger/definitions/hold.json | 4 ++-- api/v1/swagger/paths/holds.json | 6 +++--- t/db_dependent/api/v1/holds.t | 14 ++++++++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/api/v1/swagger/definitions/hold.json b/api/v1/swagger/definitions/hold.json index 2fe5b6de96..394d2f671b 100644 --- a/api/v1/swagger/definitions/hold.json +++ b/api/v1/swagger/definitions/hold.json @@ -11,7 +11,7 @@ }, "hold_date": { "type": ["string", "null"], - "format": "date", + "format": "date-time", "description": "The date the hold was placed" }, "biblio_id": { @@ -63,7 +63,7 @@ }, "expiration_date": { "type": ["string", "null"], - "format": "date", + "format": "date-time", "description": "The date the hold expires" }, "lowest_priority": { diff --git a/api/v1/swagger/paths/holds.json b/api/v1/swagger/paths/holds.json index ea5245a08e..aecb20c8e1 100644 --- a/api/v1/swagger/paths/holds.json +++ b/api/v1/swagger/paths/holds.json @@ -23,7 +23,7 @@ "in": "query", "description": "Hold", "type": "string", - "format": "date" + "format": "date-time" }, { "name": "biblio_id", @@ -202,7 +202,7 @@ "hold_date": { "description": "The date the hold was placed", "type": [ "string", "null" ], - "format": "date" + "format": "date-time" }, "item_id": { "description": "Internal item identifier", @@ -215,7 +215,7 @@ "expiration_date": { "description": "Hold end date", "type": ["string", "null"], - "format": "date" + "format": "date-time" }, "notes": { "description": "Notes related to this hold", diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index ac18877272..4f534c9d4c 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -159,7 +159,7 @@ 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 => 'rfc3339' } ), }; my $patch_data = { priority => 2, @@ -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 => 'rfc3339' })) ->json_is('/0/pickup_library_id', $branchcode); $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data ) @@ -322,15 +322,15 @@ subtest 'test AllowHoldDateInFuture' => sub { $dbh->do('DELETE FROM reserves'); - my $future_hold_date = DateTime->now->add(days => 10)->truncate( to => 'day' ); + my $future_hold_date = DateTime->now->add(days => 10); my $post_data = { patron_id => $patron_1->borrowernumber, 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 => 'rfc3339' } ), + hold_date => output_pref( { dt => $future_hold_date, dateformat => 'rfc3339' } ), }; t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); @@ -340,6 +340,8 @@ subtest 'test AllowHoldDateInFuture' => sub { ->json_has('/error'); t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 1 ); + t::lib::Mocks::mock_preference( 'HourBasedHolds', 1 ); + t::lib::Mocks::mock_preference( 'dateformat', 'rfc3339' ); # Make sure pickup location checks doesn't get in the middle my $mock_biblio = Test::MockModule->new('Koha::Biblio'); @@ -349,7 +351,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 => 'rfc3339' })); }; $schema->storage->txn_rollback; -- 2.11.0