Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 8; |
20 |
use Test::More tests => 9; |
21 |
use Test::Mojo; |
21 |
use Test::Mojo; |
22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
Lines 508-511
subtest 'PUT /holds/{hold_id}/priority tests' => sub {
Link Here
|
508 |
is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' ); |
508 |
is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' ); |
509 |
|
509 |
|
510 |
$schema->storage->txn_rollback; |
510 |
$schema->storage->txn_rollback; |
511 |
}; |
511 |
}; |
|
|
512 |
|
513 |
subtest 'add() tests (maxreserves behaviour)' => sub { |
514 |
|
515 |
plan tests => 7; |
516 |
|
517 |
$schema->storage->txn_begin; |
518 |
|
519 |
$dbh->do('DELETE FROM reserves'); |
520 |
|
521 |
Koha::CirculationRules->new->delete; |
522 |
|
523 |
my $password = 'AbcdEFG123'; |
524 |
|
525 |
my $patron = $builder->build_object( |
526 |
{ class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 1 } } ); |
527 |
$patron->set_password({ password => $password, skip_validation => 1 }); |
528 |
my $userid = $patron->userid; |
529 |
|
530 |
Koha::CirculationRules->set_rules( |
531 |
{ |
532 |
itemtype => undef, |
533 |
branchcode => undef, |
534 |
categorycode => undef, |
535 |
rules => { |
536 |
reservesallowed => 3 |
537 |
} |
538 |
} |
539 |
); |
540 |
|
541 |
Koha::CirculationRules->set_rules( |
542 |
{ |
543 |
branchcode => undef, |
544 |
categorycode => $patron->categorycode, |
545 |
rules => { |
546 |
max_holds => 4, |
547 |
} |
548 |
} |
549 |
); |
550 |
|
551 |
my $biblio_1 = $builder->build_sample_biblio; |
552 |
my $item_1 = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber }); |
553 |
my $biblio_2 = $builder->build_sample_biblio; |
554 |
my $item_2 = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber }); |
555 |
my $biblio_3 = $builder->build_sample_biblio; |
556 |
my $item_3 = $builder->build_sample_item({ biblionumber => $biblio_3->biblionumber }); |
557 |
|
558 |
# Disable logging |
559 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
560 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
561 |
t::lib::Mocks::mock_preference( 'maxreserves', 2 ); |
562 |
t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); |
563 |
|
564 |
my $post_data = { |
565 |
patron_id => $patron->borrowernumber, |
566 |
biblio_id => $biblio_1->biblionumber, |
567 |
pickup_library_id => $item_1->home_branch->branchcode, |
568 |
item_type => $item_1->itype, |
569 |
}; |
570 |
|
571 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data ) |
572 |
->status_is(201); |
573 |
|
574 |
$post_data = { |
575 |
patron_id => $patron->borrowernumber, |
576 |
biblio_id => $biblio_2->biblionumber, |
577 |
pickup_library_id => $item_2->home_branch->branchcode, |
578 |
item_id => $item_2->itemnumber |
579 |
}; |
580 |
|
581 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data ) |
582 |
->status_is(201); |
583 |
|
584 |
$post_data = { |
585 |
patron_id => $patron->borrowernumber, |
586 |
biblio_id => $biblio_3->biblionumber, |
587 |
pickup_library_id => $item_1->home_branch->branchcode, |
588 |
item_id => $item_3->itemnumber |
589 |
}; |
590 |
|
591 |
$t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data ) |
592 |
->status_is(403) |
593 |
->json_is( { error => 'Hold cannot be placed. Reason: tooManyReserves' } ); |
594 |
|
595 |
$schema->storage->txn_rollback; |
596 |
}; |
512 |
- |
|
|