From bc2a36851f9892e6fdbfc3dd92b71d22667ae3f0 Mon Sep 17 00:00:00 2001 From: Johanna Raisa Date: Tue, 3 May 2022 10:39:56 +0300 Subject: [PATCH 1/2] Bug 30661: Allow to update more hold parameters via REST API This patch adds hold_date and expiration_date to holds edit endpoint Test plan: 1) prove t/db_dependent/api/v1/holds.t Sponsored-by: Koha-Suomi Oy --- Koha/REST/V1/Holds.pm | 4 ++++ api/v1/swagger/paths/holds.yaml | 8 ++++++++ t/db_dependent/api/v1/holds.t | 34 ++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 44188363a6..0d445aa3b4 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -274,6 +274,8 @@ sub edit { $pickup_library_id //= $hold->branchcode; my $priority = $body->{priority} // $hold->priority; + my $hold_date = $body->{hold_date} // $hold->reservedate; + my $expiration_date = $body->{expiration_date} // $hold->expirationdate; # suspended_until can also be set to undef my $suspended_until = $body->{suspended_until} || $hold->suspend_until; @@ -283,6 +285,8 @@ sub edit { rank => $priority, suspend_until => $suspended_until, itemnumber => $hold->itemnumber, + reservedate => $hold_date, + expirationdate => $expiration_date, }; C4::Reserves::ModReserve($params); diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index 617eb3d9d3..f954f7dd8b 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -255,6 +255,14 @@ description: Date until which the hold has been suspended type: string format: date-time + hold_date: + description: Hold date + type: string + format: date + expiration_date: + description: Hold's expiration date + type: string + format: date additionalProperties: false consumes: - application/json diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 6665b55116..cc666c4b02 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -917,7 +917,7 @@ subtest 'pickup_locations() tests' => sub { subtest 'edit() tests' => sub { - plan tests => 39; + plan tests => 47; $schema->storage->txn_begin; @@ -972,6 +972,8 @@ subtest 'edit() tests' => sub { branchcode => $library_3->branchcode, itemnumber => undef, priority => 1, + reservedate => '2022-01-01', + expirationdate => '2022-03-01' } } ); @@ -1026,6 +1028,20 @@ subtest 'edit() tests' => sub { $biblio_hold->discard_changes; is( $biblio_hold->branchcode, $library_2->id, 'Pickup location changed correctly' ); + $biblio_hold_data = { + hold_date => '2022-01-02', + expiration_date => '2022-03-02' + }; + + $t->patch_ok( "//$userid:$password@/api/v1/holds/" + . $biblio_hold->id + => json => $biblio_hold_data ) + ->status_is(200); + + $biblio_hold->discard_changes; + is( $biblio_hold->reservedate, '2022-01-02', 'Hold date changed correctly' ); + is( $biblio_hold->expirationdate, '2022-03-02', 'Expiration date changed correctly' ); + # Test item-level holds my $item_hold = $builder->build_object( { @@ -1037,6 +1053,8 @@ subtest 'edit() tests' => sub { priority => 1, suspend => 0, suspend_until => undef, + reservedate => '2022-01-01', + expirationdate => '2022-03-01' } } ); @@ -1091,6 +1109,20 @@ subtest 'edit() tests' => sub { is( $item_hold->suspend, 0, 'Location change should not activate suspended status' ); is( $item_hold->suspend_until, undef, 'Location change should keep suspended_until be undef' ); + $item_hold_data = { + hold_date => '2022-01-02', + expiration_date => '2022-03-02' + }; + + $t->patch_ok( "//$userid:$password@/api/v1/holds/" + . $item_hold->id + => json => $item_hold_data ) + ->status_is(200); + + $item_hold->discard_changes; + is( $item_hold->reservedate, '2022-01-02', 'Hold date changed correctly' ); + is( $item_hold->expirationdate, '2022-03-02', 'Expiration date changed correctly' ); + $schema->storage->txn_rollback; }; -- 2.25.1