|
Lines 20-26
use Modern::Perl;
Link Here
|
| 20 |
use utf8; |
20 |
use utf8; |
| 21 |
use Encode; |
21 |
use Encode; |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 5; |
23 |
use Test::More tests => 6; |
| 24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
| 25 |
use Test::Mojo; |
25 |
use Test::Mojo; |
| 26 |
use Test::Warn; |
26 |
use Test::Warn; |
|
Lines 494-496
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 494 |
|
494 |
|
| 495 |
$schema->storage->txn_rollback; |
495 |
$schema->storage->txn_rollback; |
| 496 |
}; |
496 |
}; |
| 497 |
- |
497 |
|
|
|
498 |
subtest 'get_items_public() tests' => sub { |
| 499 |
|
| 500 |
plan tests => 15; |
| 501 |
|
| 502 |
$schema->storage->txn_begin; |
| 503 |
|
| 504 |
my $override_hidden_items = 0; |
| 505 |
|
| 506 |
my $mocked_category = Test::MockModule->new('Koha::Patron::Category'); |
| 507 |
$mocked_category->mock( |
| 508 |
'override_hidden_items', |
| 509 |
sub { |
| 510 |
return $override_hidden_items; |
| 511 |
} |
| 512 |
); |
| 513 |
|
| 514 |
my $rules = undef; |
| 515 |
|
| 516 |
my $mocked_context = Test::MockModule->new('C4::Context'); |
| 517 |
$mocked_context->mock( |
| 518 |
'yaml_preference', |
| 519 |
sub { |
| 520 |
return $rules; |
| 521 |
} |
| 522 |
); |
| 523 |
|
| 524 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 525 |
my $password = 'thePassword123'; |
| 526 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 527 |
$patron->discard_changes; |
| 528 |
my $userid = $patron->userid; |
| 529 |
|
| 530 |
my $biblio = $builder->build_sample_biblio(); |
| 531 |
|
| 532 |
$t->get_ok( |
| 533 |
"//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" ) |
| 534 |
->status_is(200)->json_is( '' => [], 'No items on the biblio' ); |
| 535 |
|
| 536 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id } ); |
| 537 |
my $item_2 = $builder->build_sample_item( |
| 538 |
{ biblionumber => $biblio->id, withdrawn => 1 } ); |
| 539 |
|
| 540 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" |
| 541 |
. $biblio->biblionumber |
| 542 |
. "/items" )->status_is(200)->json_is( |
| 543 |
'' => [ |
| 544 |
$item_1->to_api( { public => 1 } ), |
| 545 |
$item_2->to_api( { public => 1 } ) |
| 546 |
], |
| 547 |
'The items are returned' |
| 548 |
); |
| 549 |
|
| 550 |
$rules = { withdrawn => ['1'] }; |
| 551 |
|
| 552 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" |
| 553 |
. $biblio->biblionumber |
| 554 |
. "/items" )->status_is(200)->json_is( |
| 555 |
'' => [ $item_1->to_api( { public => 1 } ) ], |
| 556 |
'The items are returned, hidden one is not returned' |
| 557 |
); |
| 558 |
|
| 559 |
$t->get_ok( "/api/v1/public/biblios/" |
| 560 |
. $biblio->biblionumber |
| 561 |
. "/items" )->status_is(200)->json_is( |
| 562 |
'' => [ $item_1->to_api( { public => 1 } ) ], |
| 563 |
'Anonymous user, items are returned, hidden one is not returned' |
| 564 |
); |
| 565 |
|
| 566 |
|
| 567 |
$override_hidden_items = 1; |
| 568 |
|
| 569 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" |
| 570 |
. $biblio->biblionumber |
| 571 |
. "/items" )->status_is(200)->json_is( |
| 572 |
'' => [ |
| 573 |
$item_1->to_api( { public => 1 } ), |
| 574 |
$item_2->to_api( { public => 1 } ) |
| 575 |
], |
| 576 |
'The items are returned, the patron category has an override' |
| 577 |
); |
| 578 |
|
| 579 |
$schema->storage->txn_rollback; |
| 580 |
}; |