View | Details | Raw Unified | Return to bug 25662
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/holds.t (-2 / +86 lines)
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 572-574 subtest 'PUT /holds/{hold_id}/priority tests' => sub { Link Here
572
572
573
    $schema->storage->txn_rollback;
573
    $schema->storage->txn_rollback;
574
};
574
};
575
- 
575
576
subtest 'add() tests (maxreserves behaviour)' => sub {
577
578
    plan tests => 7;
579
580
    $schema->storage->txn_begin;
581
582
    $dbh->do('DELETE FROM reserves');
583
584
    Koha::CirculationRules->new->delete;
585
586
    my $password = 'AbcdEFG123';
587
588
    my $patron = $builder->build_object(
589
        { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 1 } } );
590
    $patron->set_password({ password => $password, skip_validation => 1 });
591
    my $userid = $patron->userid;
592
593
    Koha::CirculationRules->set_rules(
594
        {
595
            itemtype     => undef,
596
            branchcode   => undef,
597
            categorycode => undef,
598
            rules        => {
599
                reservesallowed => 3
600
            }
601
        }
602
    );
603
604
    Koha::CirculationRules->set_rules(
605
        {
606
            branchcode   => undef,
607
            categorycode => $patron->categorycode,
608
            rules        => {
609
                max_holds   => 4,
610
            }
611
        }
612
    );
613
614
    my $biblio_1 = $builder->build_sample_biblio;
615
    my $item_1   = $builder->build_sample_item({ biblionumber => $biblio_1->biblionumber });
616
    my $biblio_2 = $builder->build_sample_biblio;
617
    my $item_2   = $builder->build_sample_item({ biblionumber => $biblio_2->biblionumber });
618
    my $biblio_3 = $builder->build_sample_biblio;
619
    my $item_3   = $builder->build_sample_item({ biblionumber => $biblio_3->biblionumber });
620
621
    # Disable logging
622
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
623
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
624
    t::lib::Mocks::mock_preference( 'maxreserves',   2 );
625
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
626
627
    my $post_data = {
628
        patron_id => $patron->borrowernumber,
629
        biblio_id => $biblio_1->biblionumber,
630
        pickup_library_id => $item_1->home_branch->branchcode,
631
        item_type => $item_1->itype,
632
    };
633
634
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
635
      ->status_is(201);
636
637
    $post_data = {
638
        patron_id => $patron->borrowernumber,
639
        biblio_id => $biblio_2->biblionumber,
640
        pickup_library_id => $item_2->home_branch->branchcode,
641
        item_id   => $item_2->itemnumber
642
    };
643
644
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
645
      ->status_is(201);
646
647
    $post_data = {
648
        patron_id => $patron->borrowernumber,
649
        biblio_id => $biblio_3->biblionumber,
650
        pickup_library_id => $item_1->home_branch->branchcode,
651
        item_id   => $item_3->itemnumber
652
    };
653
654
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
655
      ->status_is(403)
656
      ->json_is( { error => 'Hold cannot be placed. Reason: tooManyReserves' } );
657
658
    $schema->storage->txn_rollback;
659
};

Return to bug 25662