From 47a7dcdc9550832c24a1806ef73abbc8bd906252 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 31 Mar 2023 10:12:45 +0200 Subject: [PATCH] Bug 33146: (QA follow-up) Do not delete all items in test Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/api/v1/items.t | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/t/db_dependent/api/v1/items.t b/t/db_dependent/api/v1/items.t index 27a8566e1e3..b6ddaebbfe6 100755 --- a/t/db_dependent/api/v1/items.t +++ b/t/db_dependent/api/v1/items.t @@ -27,6 +27,8 @@ use Test::Warn; use t::lib::TestBuilder; use t::lib::Mocks; +use Mojo::JSON qw(encode_json); + use C4::Auth; use Koha::Items; use Koha::Database; @@ -105,15 +107,17 @@ subtest 'list_public() tests' => sub { $schema->storage->txn_begin; - # Clean out all demo items - Koha::Items->delete(); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); - my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); my $exception = 1; - $mocked_category->mock( 'override_hidden_items', sub { - return $exception; - }); + + my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); + $mocked_category->mock( + 'override_hidden_items', + sub { + return $exception; + } + ); my $password = 'thePassword123'; $patron->set_password( { password => $password, skip_validation => 1 } ); @@ -186,28 +190,30 @@ subtest 'list_public() tests' => sub { return $rules; }); + my $query = encode_json({ item_id => [ $item_1->id, $item_2->id, $item_3->id, $item_4->id, $item_5->id, $item_6->id ] }); + subtest 'anonymous access' => sub { plan tests => 21; t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); - my $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; + my $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; is( scalar @{ $res }, 6, 'No rules set, hidelostitems unset, all items returned'); t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); - $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; + $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; is( scalar @{ $res }, 3, 'No rules set, hidelostitems set, 3 items hidden'); t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); $rules = { biblionumber => [ $biblio->biblionumber ] }; - $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; + $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; is( scalar @{ $res }, 0, 'Biblionumber rule set, hidelostitems unset, all items hidden'); $rules = { withdrawn => [ 1, 2 ] }; - $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; + $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; is( scalar @{ $res }, 4, 'Withdrawn rule set, hidelostitems unset, 2 items hidden'); $rules = { itype => [ $itype_1->itemtype ] }; - $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; + $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; is( scalar @{ $res }, 2, 'Itype rule set, hidelostitems unset, 4 items hidden'); $rules = { withdrawn => [ 1 ] }; @@ -228,7 +234,7 @@ subtest 'list_public() tests' => sub { t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); $rules = { withdrawn => [ 1, 2 ] }; - my $res = $t->get_ok("//$userid:$password@/api/v1/public/items") + my $res = $t->get_ok("//$userid:$password@/api/v1/public/items?q=" . $query) ->status_is(200)->tx->res->json; is( scalar @{$res}, -- 2.40.0