From f4d10b8bad04285b4475aeb2e3211158aac46137 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 4 May 2021 14:56:24 +0200 Subject: [PATCH] Bug 28254: Simplify tests This is only cosmetic, and maybe personal preferences. It seems easier to create the library object with the pickup_library we want to use. --- t/db_dependent/api/v1/holds.t | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/t/db_dependent/api/v1/holds.t b/t/db_dependent/api/v1/holds.t index beaaee5110b..49cd3a7df73 100755 --- a/t/db_dependent/api/v1/holds.t +++ b/t/db_dependent/api/v1/holds.t @@ -1142,9 +1142,13 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { my $password = 'AbcdEFG123'; - my $library_1 = $builder->build_object({ class => 'Koha::Libraries' }); - my $library_2 = $builder->build_object({ class => 'Koha::Libraries' }); - my $library_3 = $builder->build_object({ class => 'Koha::Libraries' }); + # library_1 and library_2 are available pickup locations, not library_3 + my $library_1 = $builder->build_object( + { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); + my $library_2 = $builder->build_object( + { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); + my $library_3 = $builder->build_object( + { class => 'Koha::Libraries', value => { pickup_location => 0 } } ); my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); @@ -1165,18 +1169,6 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); - my $libraries_query = { branchcode => [ $library_1->branchcode, $library_2->branchcode ] }; - - my $mocked_biblio = Test::MockModule->new('Koha::Biblio'); - $mocked_biblio->mock( 'pickup_locations', sub { - return Koha::Libraries->search($libraries_query); - }); - - my $mocked_item = Test::MockModule->new('Koha::Item'); - $mocked_item->mock( 'pickup_locations', sub { - return Koha::Libraries->search($libraries_query); - }); - my $biblio = $builder->build_sample_biblio; my $item = $builder->build_sample_item( { @@ -1206,8 +1198,6 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' ); - $libraries_query = { branchcode => $library_1->branchcode }; - $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } ) @@ -1229,12 +1219,10 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { ) ); - $libraries_query = { branchcode => $library_1->branchcode }; - # Attempt to use an invalid pickup locations ends in 400 $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id - . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) + . "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } ) ->status_is(400) ->json_is({ error => '[The supplied pickup location is not valid]' }); @@ -1255,12 +1243,6 @@ subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); - $libraries_query = { - branchcode => { - '-in' => [ $library_1->branchcode, $library_2->branchcode ] - } - }; - $t->put_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } ) -- 2.20.1