|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 5; |
22 |
use Test::More tests => 6; |
| 23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
| 24 |
use Test::Mojo; |
24 |
use Test::Mojo; |
| 25 |
use Test::Warn; |
25 |
use Test::Warn; |
|
Lines 30-35
use t::lib::Mocks;
Link Here
|
| 30 |
use Mojo::JSON qw(encode_json); |
30 |
use Mojo::JSON qw(encode_json); |
| 31 |
|
31 |
|
| 32 |
use C4::Auth; |
32 |
use C4::Auth; |
|
|
33 |
use C4::Circulation; |
| 33 |
use Koha::Items; |
34 |
use Koha::Items; |
| 34 |
use Koha::Database; |
35 |
use Koha::Database; |
| 35 |
|
36 |
|
|
Lines 572-574
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 572 |
|
573 |
|
| 573 |
$schema->storage->txn_rollback; |
574 |
$schema->storage->txn_rollback; |
| 574 |
}; |
575 |
}; |
| 575 |
- |
576 |
|
|
|
577 |
subtest 'checkout() tests' => sub { |
| 578 |
|
| 579 |
plan tests => 27; |
| 580 |
|
| 581 |
$schema->storage->txn_begin; |
| 582 |
|
| 583 |
my $item = $builder->build_sample_item; |
| 584 |
my $item2 = $builder->build_sample_item; |
| 585 |
my $patron = $builder->build_object( |
| 586 |
{ |
| 587 |
class => 'Koha::Patrons', |
| 588 |
value => { flags => 4 } |
| 589 |
} |
| 590 |
); |
| 591 |
|
| 592 |
# Make sure we have at least 10 items |
| 593 |
for ( 1..10 ) { |
| 594 |
$builder->build_sample_item; |
| 595 |
} |
| 596 |
|
| 597 |
my $nonprivilegedpatron = $builder->build_object( |
| 598 |
{ |
| 599 |
class => 'Koha::Patrons', |
| 600 |
value => { flags => 0 } |
| 601 |
} |
| 602 |
); |
| 603 |
|
| 604 |
my $password = 'thePassword123'; |
| 605 |
|
| 606 |
$nonprivilegedpatron->set_password( |
| 607 |
{ password => $password, skip_validation => 1 } ); |
| 608 |
|
| 609 |
my $userid = $nonprivilegedpatron->userid; |
| 610 |
my $itemid = $item->id; |
| 611 |
my $itemid2 = $item2->id; |
| 612 |
my $patronid = $patron->borrowernumber; |
| 613 |
my $non_existent_code = $item->itemnumber; |
| 614 |
|
| 615 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$patronid" ) |
| 616 |
->status_is(403) |
| 617 |
->json_is( |
| 618 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
| 619 |
|
| 620 |
$t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code ) |
| 621 |
->status_is(403) |
| 622 |
->json_is( |
| 623 |
'/error' => 'Authorization failure. Missing required permission(s).' ); |
| 624 |
|
| 625 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 626 |
$userid = $patron->userid; |
| 627 |
|
| 628 |
$t->get_ok( "//$userid:$password@/api/v1/items?_per_page=10" ) |
| 629 |
->status_is( 200, 'SWAGGER3.2.2' ); |
| 630 |
|
| 631 |
my $response_count = scalar @{ $t->tx->res->json }; |
| 632 |
|
| 633 |
is( $response_count, 10, 'The API returns 10 items' ); |
| 634 |
|
| 635 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
| 636 |
->status_is(200) |
| 637 |
->json_is( '' => [ $item->to_api ], 'SWAGGER3.3.2'); |
| 638 |
|
| 639 |
$patron->flags(1)->store; |
| 640 |
my $deleted_patron_id = $nonprivilegedpatron->id; |
| 641 |
$nonprivilegedpatron->delete; |
| 642 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemid/checkout/$deleted_patron_id" ) |
| 643 |
->status_is(400) |
| 644 |
->json_is( '/error' => 'Patron not found' ); |
| 645 |
|
| 646 |
my $barcode = $item->barcode; |
| 647 |
$item->delete; |
| 648 |
|
| 649 |
$t->post_ok("//$userid:$password@/api/v1/items/$itemid/checkout/$patronid") |
| 650 |
->status_is(404); |
| 651 |
|
| 652 |
$t->get_ok( "//$userid:$password@/api/v1/items?external_id=" . $item->barcode ) |
| 653 |
->status_is(200) |
| 654 |
->json_is( '' => [] ); |
| 655 |
|
| 656 |
$t->get_ok( "//$userid:$password@/api/v1/items/" . $non_existent_code ) |
| 657 |
->status_is(404) |
| 658 |
->json_is( |
| 659 |
'/error' => 'Item not found' ); |
| 660 |
|
| 661 |
is( $patron->checkouts->count, 0); |
| 662 |
|
| 663 |
$t->post_ok( "//$userid:$password@/api/v1/items/$itemid2/checkout/$patronid") |
| 664 |
->status_is(201); |
| 665 |
|
| 666 |
is( $patron->checkouts->count, 1); |
| 667 |
|
| 668 |
$schema->storage->txn_rollback; |
| 669 |
}; |