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

(-)a/t/db_dependent/api/v1/holds.t (-2 / +107 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 10;
21
use Test::MockModule;
21
use Test::Mojo;
22
use Test::Mojo;
22
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
23
use t::lib::Mocks;
24
use t::lib::Mocks;
Lines 671-673 subtest 'add() tests (maxreserves behaviour)' => sub { Link Here
671
672
672
    $schema->storage->txn_rollback;
673
    $schema->storage->txn_rollback;
673
};
674
};
674
- 
675
676
subtest 'pickup_locations() tests' => sub {
677
678
    plan tests => 6;
679
680
    $schema->storage->txn_begin;
681
682
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'A' } });
683
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'B' } });
684
    my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'C' } });
685
686
    my $patron = $builder->build_object(
687
        {
688
            class => 'Koha::Patrons',
689
            value => { userid => 'tomasito', flags => 1 }
690
        }
691
    );
692
    $patron->set_password( { password => $password, skip_validation => 1 } );
693
    my $userid = $patron->userid;
694
695
    my $item_class = Test::MockModule->new('Koha::Item');
696
    $item_class->mock(
697
        'pickup_locations',
698
        sub {
699
            my ( $self, $params ) = @_;
700
            my $mock_patron = $params->{patron};
701
            is( $mock_patron->borrowernumber,
702
                $patron->borrowernumber, 'Patron passed correctly' );
703
            return Koha::Libraries->search(
704
                {
705
                    branchcode => {
706
                        '-in' => [
707
                            $library_1->branchcode,
708
                            $library_2->branchcode
709
                        ]
710
                    }
711
                },
712
                {   # we make sure no surprises in the order of the result
713
                    order_by => { '-asc' => 'marcorgcode' }
714
                }
715
            );
716
        }
717
    );
718
719
    my $biblio_class = Test::MockModule->new('Koha::Biblio');
720
    $biblio_class->mock(
721
        'pickup_locations',
722
        sub {
723
            my ( $self, $params ) = @_;
724
            my $mock_patron = $params->{patron};
725
            is( $mock_patron->borrowernumber,
726
                $patron->borrowernumber, 'Patron passed correctly' );
727
            return Koha::Libraries->search(
728
                {
729
                    branchcode => {
730
                        '-in' => [
731
                            $library_2->branchcode,
732
                            $library_3->branchcode
733
                        ]
734
                    }
735
                },
736
                {   # we make sure no surprises in the order of the result
737
                    order_by => { '-asc' => 'marcorgcode' }
738
                }
739
            );
740
        }
741
    );
742
743
    my $item = $builder->build_sample_item;
744
745
    # biblio-level hold
746
    my $hold_1 = $builder->build_object(
747
        {
748
            class => 'Koha::Holds',
749
            value => {
750
                itemnumber     => undef,
751
                biblionumber   => $item->biblionumber,
752
                borrowernumber => $patron->borrowernumber
753
            }
754
        }
755
    );
756
    # item-level hold
757
    my $hold_2 = $builder->build_object(
758
        {
759
            class => 'Koha::Holds',
760
            value => {
761
                itemnumber     => $item->itemnumber,
762
                biblionumber   => $item->biblionumber,
763
                borrowernumber => $patron->borrowernumber
764
            }
765
        }
766
    );
767
768
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
769
          . $hold_1->id
770
          . "/pickup_locations" )
771
      ->json_is( [ $library_2->to_api, $library_3->to_api ] );
772
773
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
774
          . $hold_2->id
775
          . "/pickup_locations" )
776
      ->json_is( [ $library_1->to_api, $library_2->to_api ] );
777
778
    $schema->storage->txn_rollback;
779
};

Return to bug 26988