From ccfedaa5d9039decb5cf61264621d360e75b94ac Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 13 Jun 2022 11:46:20 -0300 Subject: [PATCH] Bug 30780: Regression tests This patch lowers the used permissions on the suspend/resume tests, and adds tests for fine-grained permissions on cancelling a hold. Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/holds.t | 70 ++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index 471a2462f4..6665b55116 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 => 13; +use Test::More tests => 14; use Test::MockModule; use Test::Mojo; use t::lib::TestBuilder; @@ -461,7 +461,18 @@ subtest 'suspend and resume tests' => sub { my $password = 'AbcdEFG123'; my $patron = $builder->build_object( - { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 1 } } ); + { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 0 } } ); + $builder->build( + { + source => 'UserPermission', + value => { + borrowernumber => $patron->borrowernumber, + module_bit => 6, + code => 'place_holds', + }, + } + ); + $patron->set_password({ password => $password, skip_validation => 1 }); my $userid = $patron->userid; @@ -1363,3 +1374,58 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'delete() tests' => sub { + + plan tests => 3; + + $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/" . $hold->id ) + ->status_is(204, 'SWAGGER3.2.4') + ->content_is('', 'SWAGGER3.3.4'); + + $schema->storage->txn_rollback; +}; -- 2.39.2