Lines 27-32
use Test::Warn;
Link Here
|
27 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
28 |
use t::lib::Mocks; |
28 |
use t::lib::Mocks; |
29 |
|
29 |
|
|
|
30 |
use Mojo::JSON qw(encode_json); |
31 |
|
30 |
use C4::Auth; |
32 |
use C4::Auth; |
31 |
use Koha::Items; |
33 |
use Koha::Items; |
32 |
use Koha::Database; |
34 |
use Koha::Database; |
Lines 105-119
subtest 'list_public() tests' => sub {
Link Here
|
105 |
|
107 |
|
106 |
$schema->storage->txn_begin; |
108 |
$schema->storage->txn_begin; |
107 |
|
109 |
|
108 |
# Clean out all demo items |
110 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
109 |
Koha::Items->delete(); |
|
|
110 |
|
111 |
|
111 |
my $patron = $builder->build_object({ class => 'Koha::Patrons' }); |
|
|
112 |
my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); |
113 |
my $exception = 1; |
112 |
my $exception = 1; |
114 |
$mocked_category->mock( 'override_hidden_items', sub { |
113 |
|
115 |
return $exception; |
114 |
my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); |
116 |
}); |
115 |
$mocked_category->mock( |
|
|
116 |
'override_hidden_items', |
117 |
sub { |
118 |
return $exception; |
119 |
} |
120 |
); |
117 |
|
121 |
|
118 |
my $password = 'thePassword123'; |
122 |
my $password = 'thePassword123'; |
119 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
123 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
Lines 186-213
subtest 'list_public() tests' => sub {
Link Here
|
186 |
return $rules; |
190 |
return $rules; |
187 |
}); |
191 |
}); |
188 |
|
192 |
|
|
|
193 |
my $query = encode_json({ item_id => [ $item_1->id, $item_2->id, $item_3->id, $item_4->id, $item_5->id, $item_6->id ] }); |
194 |
|
189 |
subtest 'anonymous access' => sub { |
195 |
subtest 'anonymous access' => sub { |
190 |
plan tests => 21; |
196 |
plan tests => 21; |
191 |
|
197 |
|
192 |
t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); |
198 |
t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); |
193 |
my $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; |
199 |
my $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; |
194 |
is( scalar @{ $res }, 6, 'No rules set, hidelostitems unset, all items returned'); |
200 |
is( scalar @{ $res }, 6, 'No rules set, hidelostitems unset, all items returned'); |
195 |
|
201 |
|
196 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
202 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
197 |
$res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; |
203 |
$res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; |
198 |
is( scalar @{ $res }, 3, 'No rules set, hidelostitems set, 3 items hidden'); |
204 |
is( scalar @{ $res }, 3, 'No rules set, hidelostitems set, 3 items hidden'); |
199 |
|
205 |
|
200 |
t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); |
206 |
t::lib::Mocks::mock_preference( 'hidelostitems', 0 ); |
201 |
$rules = { biblionumber => [ $biblio->biblionumber ] }; |
207 |
$rules = { biblionumber => [ $biblio->biblionumber ] }; |
202 |
$res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; |
208 |
$res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; |
203 |
is( scalar @{ $res }, 0, 'Biblionumber rule set, hidelostitems unset, all items hidden'); |
209 |
is( scalar @{ $res }, 0, 'Biblionumber rule set, hidelostitems unset, all items hidden'); |
204 |
|
210 |
|
205 |
$rules = { withdrawn => [ 1, 2 ] }; |
211 |
$rules = { withdrawn => [ 1, 2 ] }; |
206 |
$res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; |
212 |
$res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; |
207 |
is( scalar @{ $res }, 4, 'Withdrawn rule set, hidelostitems unset, 2 items hidden'); |
213 |
is( scalar @{ $res }, 4, 'Withdrawn rule set, hidelostitems unset, 2 items hidden'); |
208 |
|
214 |
|
209 |
$rules = { itype => [ $itype_1->itemtype ] }; |
215 |
$rules = { itype => [ $itype_1->itemtype ] }; |
210 |
$res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json; |
216 |
$res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json; |
211 |
is( scalar @{ $res }, 2, 'Itype rule set, hidelostitems unset, 4 items hidden'); |
217 |
is( scalar @{ $res }, 2, 'Itype rule set, hidelostitems unset, 4 items hidden'); |
212 |
|
218 |
|
213 |
$rules = { withdrawn => [ 1 ] }; |
219 |
$rules = { withdrawn => [ 1 ] }; |
Lines 228-234
subtest 'list_public() tests' => sub {
Link Here
|
228 |
|
234 |
|
229 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
235 |
t::lib::Mocks::mock_preference( 'hidelostitems', 1 ); |
230 |
$rules = { withdrawn => [ 1, 2 ] }; |
236 |
$rules = { withdrawn => [ 1, 2 ] }; |
231 |
my $res = $t->get_ok("//$userid:$password@/api/v1/public/items") |
237 |
my $res = $t->get_ok("//$userid:$password@/api/v1/public/items?q=" . $query) |
232 |
->status_is(200)->tx->res->json; |
238 |
->status_is(200)->tx->res->json; |
233 |
is( |
239 |
is( |
234 |
scalar @{$res}, |
240 |
scalar @{$res}, |
235 |
- |
|
|