Bugzilla – Attachment 184863 Details for
Bug 40550
Add /holds/cancellation_bulk endpoint
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40550: Add API tests
Bug-40550-Add-API-tests.patch (text/plain), 4.57 KB, created by
Pedro Amorim
on 2025-07-30 11:36:40 UTC
(
hide
)
Description:
Bug 40550: Add API tests
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2025-07-30 11:36:40 UTC
Size:
4.57 KB
patch
obsolete
>From a781e574f08da55bea7b170f62239c39f44d9a19 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@openfifth.co.uk> >Date: Wed, 30 Jul 2025 11:27:49 +0000 >Subject: [PATCH] Bug 40550: Add API tests > >prove t/db_dependent/api/v1/holds.t >--- > t/db_dependent/api/v1/holds.t | 101 +++++++++++++++++++++++++++++++++- > 1 file changed, 100 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t >index e98d8b125e0..28518784b41 100755 >--- a/t/db_dependent/api/v1/holds.t >+++ b/t/db_dependent/api/v1/holds.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 18; >+use Test::More tests => 19; > use Test::NoWarnings; > use Test::MockModule; > use Test::Mojo; >@@ -38,6 +38,7 @@ use Koha::Biblios; > use Koha::Biblioitems; > use Koha::Items; > use Koha::CirculationRules; >+use Koha::Old::Holds; > use Koha::Patron::Debarments qw(AddDebarment); > > my $schema = Koha::Database->new->schema; >@@ -1834,6 +1835,104 @@ subtest 'delete() tests' => sub { > $schema->storage->txn_rollback; > }; > >+subtest 'delete_bulk) tests' => sub { >+ >+ plan tests => 12; >+ >+ $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 $userid = $patron->userid; >+ >+ # Only have 'place_holds' subpermission >+ $builder->build( >+ { >+ source => 'UserPermission', >+ value => { >+ borrowernumber => $patron->borrowernumber, >+ module_bit => 6, >+ code => 'place_holds', >+ }, >+ } >+ ); >+ >+ # Disable logging >+ t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >+ t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $item = $builder->build_sample_item( >+ { >+ biblionumber => $biblio->biblionumber, >+ library => $patron->branchcode >+ } >+ ); >+ >+ # Add a hold >+ my $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/cancellation_bulk" => json => { hold_ids => [ $hold->id ] } ) >+ ->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); >+ >+ is( $hold->get_from_storage, undef, "Hold has been successfully deleted" ); >+ >+ my $hold_2 = Koha::Holds->find( >+ AddReserve( >+ { >+ branchcode => $patron->branchcode, >+ borrowernumber => $patron->borrowernumber, >+ biblionumber => $biblio->biblionumber, >+ priority => 1, >+ itemnumber => undef, >+ } >+ ) >+ ); >+ >+ # Prevent warning 'No reserves HOLD_CANCELLATION letter transported by email' >+ my $mock_letters = Test::MockModule->new('C4::Letters'); >+ $mock_letters->mock( 'GetPreparedLetter', sub { return } ); >+ >+ $t->delete_ok( "//$userid:$password@/api/v1/holds/cancellation_bulk" => json => >+ { hold_ids => [ $hold_2->id ], cancellation_reason => 'DAMAGED' } )->status_is( 204, 'REST3.2.4' ) >+ ->content_is( '', 'REST3.3.4' ); >+ >+ my $old_hold_2 = Koha::Old::Holds->find( $hold_2->id ); >+ is( $old_hold_2->cancellation_reason, 'DAMAGED', "Hold successfully deleted with provided cancellation reason" ); >+ >+ my $hold_3 = 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/cancellation_bulk" => json => >+ { hold_ids => [ $hold_2->id, $hold_3->id ], cancellation_reason => 'DAMAGED' } ) >+ ->status_is( 404, 'REST3.2.4' ) >+ ->content_is( '{"error":"Hold not found","error_code":"not_found"}', 'REST3.3.4' ); >+ >+ isnt( $hold_3->get_from_storage, undef, "Hold 3 has not been deleted because cancellation_bulk failed." ); >+ >+ $schema->storage->txn_rollback; >+}; >+ > subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { > > plan tests => 5; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40550
: 184863 |
184864