From 13f5089d48b7cffa142f4c2c4e10e3437a201e29 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 24 Jul 2023 16:08:22 -0300 Subject: [PATCH] Bug 34365: Unit tests Signed-off-by: Emily Lamancusa --- api/v1/swagger/paths/holds.yaml | 12 +++++++ t/db_dependent/api/v1/holds.t | 64 +++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/api/v1/swagger/paths/holds.yaml b/api/v1/swagger/paths/holds.yaml index 528656748b..72bc7f77a2 100644 --- a/api/v1/swagger/paths/holds.yaml +++ b/api/v1/swagger/paths/holds.yaml @@ -379,9 +379,21 @@ summary: Cancel hold parameters: - $ref: "../swagger.yaml#/parameters/hold_id_pp" + - name: x-koha-override + in: header + required: false + description: Overrides list sent as a request header + type: array + items: + type: string + enum: + - cancellation-request-flow + collectionFormat: csv produces: - application/json responses: + "202": + description: Hold request recorded "204": description: Hold deleted "401": diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index adc5429660..81c8e43939 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -1408,13 +1408,13 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { subtest 'delete() tests' => sub { - plan tests => 3; + plan tests => 13; $schema->storage->txn_begin; my $password = 'AbcdEFG123'; - my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 } }); - $patron->set_password({ password => $password, skip_validation => 1 }); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); + $patron->set_password( { password => $password, skip_validation => 1 } ); my $userid = $patron->userid; # Only have 'place_holds' subpermission @@ -1454,9 +1454,61 @@ subtest 'delete() tests' => sub { ) ); - $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id ) - ->status_is(204, 'SWAGGER3.2.4') - ->content_is('', 'SWAGGER3.3.4'); + $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id )->status_is( 204, 'SWAGGER3.2.4' ) + ->content_is( '', 'SWAGGER3.3.4' ); + + $hold = Koha::Holds->find( + AddReserve( + { + branchcode => $patron->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1, + itemnumber => undef, + } + ) + ); + + $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id => { 'x-koha-override' => q{} } ) + ->status_is( 204, 'Same behavior if header not set' )->content_is(''); + + $hold = Koha::Holds->find( + AddReserve( + { + branchcode => $patron->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1, + itemnumber => undef, + } + ) + ); + + $t->delete_ok( + "//$userid:$password@/api/v1/holds/" . $hold->id => { 'x-koha-override' => q{cancellation-request-flow} } ) + ->status_is( 204, 'Same behavior if header set but hold not waiting' )->content_is(''); + + $hold = Koha::Holds->find( + AddReserve( + { + branchcode => $patron->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1, + itemnumber => undef, + } + ) + ); + + $hold->set_waiting; + + is( $hold->cancellation_requests->count, 0 ); + + $t->delete_ok( + "//$userid:$password@/api/v1/holds/" . $hold->id => { 'x-koha-override' => q{cancellation-request-flow} } ) + ->status_is( 202, 'Cancellation request accepted' ); + + is( $hold->cancellation_requests->count, 1 ); $schema->storage->txn_rollback; }; -- 2.34.1