|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 15; |
20 |
use Test::More tests => 16; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
|
Lines 697-704
subtest 'add() tests (maxreserves behaviour)' => sub {
Link Here
|
| 697 |
item_id => $item_3->itemnumber |
697 |
item_id => $item_3->itemnumber |
| 698 |
}; |
698 |
}; |
| 699 |
|
699 |
|
| 700 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )->status_is(403) |
700 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )->status_is(409)->json_is( |
| 701 |
->json_is( { error => 'Hold cannot be placed. Reason: tooManyReserves' } ); |
701 |
{ |
|
|
702 |
error => 'Hold cannot be placed. Reason: hold_limit', |
| 703 |
error_code => 'hold_limit' |
| 704 |
} |
| 705 |
); |
| 702 |
|
706 |
|
| 703 |
t::lib::Mocks::mock_preference( 'maxreserves', 0 ); |
707 |
t::lib::Mocks::mock_preference( 'maxreserves', 0 ); |
| 704 |
|
708 |
|
|
Lines 717-722
subtest 'add() tests (maxreserves behaviour)' => sub {
Link Here
|
| 717 |
$schema->storage->txn_rollback; |
721 |
$schema->storage->txn_rollback; |
| 718 |
}; |
722 |
}; |
| 719 |
|
723 |
|
|
|
724 |
subtest 'add() + can_place_holds() tests' => sub { |
| 725 |
|
| 726 |
plan tests => 30; |
| 727 |
|
| 728 |
$schema->storage->txn_begin; |
| 729 |
|
| 730 |
my $password = 'AbcdEFG123'; |
| 731 |
|
| 732 |
my $library = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 733 |
my $patron = |
| 734 |
$builder->build_object( { class => 'Koha::Patrons', value => { branchcode => $library->id, flags => 1 } } ); |
| 735 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 736 |
my $userid = $patron->userid; |
| 737 |
|
| 738 |
my $current_message; |
| 739 |
my $patron_mock = Test::MockModule->new('Koha::Patron'); |
| 740 |
|
| 741 |
$patron_mock->mock( |
| 742 |
'can_place_holds', |
| 743 |
sub { |
| 744 |
return Koha::Result::Boolean->new(0)->add_message( { type => 'error', message => $current_message } ); |
| 745 |
} |
| 746 |
); |
| 747 |
|
| 748 |
my $item = $builder->build_sample_item( { library => $library->id } ); |
| 749 |
|
| 750 |
my @messages = qw( |
| 751 |
expired |
| 752 |
debt_limit |
| 753 |
bad_address |
| 754 |
card_lost |
| 755 |
restricted |
| 756 |
hold_limit); |
| 757 |
|
| 758 |
foreach my $message (@messages) { |
| 759 |
|
| 760 |
$current_message = $message; |
| 761 |
|
| 762 |
my $post_data = { |
| 763 |
patron_id => $patron->id, |
| 764 |
biblio_id => $item->biblio->id, |
| 765 |
pickup_library_id => $item->holdingbranch, |
| 766 |
item_id => $item->id |
| 767 |
}; |
| 768 |
|
| 769 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data ) |
| 770 |
->status_is( 409, "Expected error related to '$message'" ) |
| 771 |
->json_is( { error => "Hold cannot be placed. Reason: $message", error_code => $message } ); |
| 772 |
|
| 773 |
my $hold_id = |
| 774 |
$t->post_ok( |
| 775 |
"//$userid:$password@/api/v1/holds" => { 'x-koha-override' => $message } => json => $post_data ) |
| 776 |
->status_is( 201, "Override works for '$message'" )->tx->res->json->{hold_id}; |
| 777 |
|
| 778 |
Koha::Holds->find($hold_id)->delete(); |
| 779 |
} |
| 780 |
|
| 781 |
$schema->storage->txn_rollback; |
| 782 |
}; |
| 783 |
|
| 720 |
subtest 'pickup_locations() tests' => sub { |
784 |
subtest 'pickup_locations() tests' => sub { |
| 721 |
|
785 |
|
| 722 |
plan tests => 15; |
786 |
plan tests => 15; |
| 723 |
- |
|
|