From d3a71a446ab6cbe3a08c84ae051e707918a05798 Mon Sep 17 00:00:00 2001 From: Johanna Raisa Date: Tue, 3 May 2022 10:39:56 +0300 Subject: [PATCH] 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 Signed-off-by: David Nind Signed-off-by: Pedro Amorim Signed-off-by: Katrin Fischer --- Koha/REST/V1/Holds.pm | 16 +++++++---- api/v1/swagger/paths/holds.yaml | 8 ++++++ t/db_dependent/api/v1/holds.t | 50 +++++++++++++++++++++++++-------- 3 files changed, 58 insertions(+), 16 deletions(-) diff --git a/Koha/REST/V1/Holds.pm b/Koha/REST/V1/Holds.pm index 4d3c71684a..13f24b86f8 100644 --- a/Koha/REST/V1/Holds.pm +++ b/Koha/REST/V1/Holds.pm @@ -276,17 +276,23 @@ 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; my $params = { - reserve_id => $hold->id, - branchcode => $pickup_library_id, - rank => $priority, - suspend_until => $suspended_until, - itemnumber => $hold->itemnumber, + reserve_id => $hold->id, + branchcode => $pickup_library_id, + rank => $priority, + suspend_until => $suspended_until, + itemnumber => $hold->itemnumber, + reservedate => $hold_date, + expirationdate => $expiration_date, }; + C4::Reserves::ModReserve($params); $hold->discard_changes; # refresh diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index 519f7ac0d7..532c03d162 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -287,6 +287,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 95c9a8cc2a..7562509894 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; @@ -968,10 +968,12 @@ subtest 'edit() tests' => sub { { class => "Koha::Holds", value => { - biblionumber => $biblio->biblionumber, - branchcode => $library_3->branchcode, - itemnumber => undef, - priority => 1, + biblionumber => $biblio->biblionumber, + branchcode => $library_3->branchcode, + itemnumber => undef, + priority => 1, + reservedate => '2022-01-01', + expirationdate => '2022-03-01' } } ); @@ -1026,17 +1028,32 @@ 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( { class => "Koha::Holds", value => { - biblionumber => $biblio->biblionumber, - branchcode => $library_3->branchcode, - itemnumber => $item->itemnumber, - priority => 1, - suspend => 0, - suspend_until => undef, + biblionumber => $biblio->biblionumber, + branchcode => $library_3->branchcode, + itemnumber => $item->itemnumber, + priority => 1, + suspend => 0, + suspend_until => undef, + reservedate => '2022-01-01', + expirationdate => '2022-03-01' } } ); @@ -1091,6 +1108,17 @@ 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.39.5