Lines 767-792
subtest 'add() tests (maxreserves behaviour)' => sub {
Link Here
|
767 |
|
767 |
|
768 |
subtest 'pickup_locations() tests' => sub { |
768 |
subtest 'pickup_locations() tests' => sub { |
769 |
|
769 |
|
770 |
plan tests => 12; |
770 |
plan tests => 15; |
771 |
|
771 |
|
772 |
$schema->storage->txn_begin; |
772 |
$schema->storage->txn_begin; |
773 |
|
773 |
|
774 |
t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); |
774 |
t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 ); |
775 |
|
775 |
|
776 |
# Small trick to ease testing |
776 |
# Small trick to ease testing |
777 |
Koha::Libraries->search->update({ pickup_location => 0 }); |
777 |
Koha::Libraries->search->update( { pickup_location => 0 } ); |
778 |
|
778 |
|
779 |
my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'A', pickup_location => 1 } }); |
779 |
my @libraries; |
780 |
my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'B', pickup_location => 1 } }); |
780 |
for my $marcorgcode ( 'A' .. 'Z' ) { |
781 |
my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'C', pickup_location => 1 } }); |
781 |
my $is_pickup_location = $marcorgcode ne 'Z' ? 1 : 0; |
782 |
|
782 |
my $library = $builder->build_object( |
783 |
my $library_1_api = $library_1->to_api(); |
783 |
{ |
784 |
my $library_2_api = $library_2->to_api(); |
784 |
class => 'Koha::Libraries', |
785 |
my $library_3_api = $library_3->to_api(); |
785 |
value => { marcorgcode => $marcorgcode, pickup_location => $is_pickup_location } |
786 |
|
786 |
} |
787 |
$library_1_api->{needs_override} = Mojo::JSON->false; |
787 |
); |
788 |
$library_2_api->{needs_override} = Mojo::JSON->false; |
788 |
my $library_api = $library->to_api; |
789 |
$library_3_api->{needs_override} = Mojo::JSON->false; |
789 |
$library_api->{needs_override} = Mojo::JSON->false; |
|
|
790 |
push @libraries, $library_api; |
791 |
} |
790 |
|
792 |
|
791 |
my $patron = $builder->build_object( |
793 |
my $patron = $builder->build_object( |
792 |
{ |
794 |
{ |
Lines 813-830
subtest 'pickup_locations() tests' => sub {
Link Here
|
813 |
sub { |
815 |
sub { |
814 |
my ( $self, $params ) = @_; |
816 |
my ( $self, $params ) = @_; |
815 |
my $mock_patron = $params->{patron}; |
817 |
my $mock_patron = $params->{patron}; |
816 |
is( $mock_patron->borrowernumber, |
818 |
is( |
817 |
$patron->borrowernumber, 'Patron passed correctly' ); |
819 |
$mock_patron->borrowernumber, |
|
|
820 |
$patron->borrowernumber, 'Patron passed correctly' |
821 |
); |
818 |
return Koha::Libraries->search( |
822 |
return Koha::Libraries->search( |
819 |
{ |
823 |
{ |
820 |
branchcode => { |
824 |
branchcode => { |
821 |
'-in' => [ |
825 |
'-in' => [ |
822 |
$library_1->branchcode, |
826 |
$libraries[0]->{library_id}, |
823 |
$library_2->branchcode |
827 |
$libraries[1]->{library_id}, |
824 |
] |
828 |
] |
825 |
} |
829 |
} |
826 |
}, |
830 |
}, |
827 |
{ # we make sure no surprises in the order of the result |
831 |
{ # we make sure no surprises in the order of the result |
828 |
order_by => { '-asc' => 'marcorgcode' } |
832 |
order_by => { '-asc' => 'marcorgcode' } |
829 |
} |
833 |
} |
830 |
); |
834 |
); |
Lines 837-854
subtest 'pickup_locations() tests' => sub {
Link Here
|
837 |
sub { |
841 |
sub { |
838 |
my ( $self, $params ) = @_; |
842 |
my ( $self, $params ) = @_; |
839 |
my $mock_patron = $params->{patron}; |
843 |
my $mock_patron = $params->{patron}; |
840 |
is( $mock_patron->borrowernumber, |
844 |
is( |
841 |
$patron->borrowernumber, 'Patron passed correctly' ); |
845 |
$mock_patron->borrowernumber, |
|
|
846 |
$patron->borrowernumber, 'Patron passed correctly' |
847 |
); |
842 |
return Koha::Libraries->search( |
848 |
return Koha::Libraries->search( |
843 |
{ |
849 |
{ |
844 |
branchcode => { |
850 |
branchcode => { |
845 |
'-in' => [ |
851 |
'-in' => [ |
846 |
$library_2->branchcode, |
852 |
$libraries[1]->{library_id}, |
847 |
$library_3->branchcode |
853 |
$libraries[2]->{library_id}, |
848 |
] |
854 |
] |
849 |
} |
855 |
} |
850 |
}, |
856 |
}, |
851 |
{ # we make sure no surprises in the order of the result |
857 |
{ # we make sure no surprises in the order of the result |
852 |
order_by => { '-asc' => 'marcorgcode' } |
858 |
order_by => { '-asc' => 'marcorgcode' } |
853 |
} |
859 |
} |
854 |
); |
860 |
); |
Lines 868-873
subtest 'pickup_locations() tests' => sub {
Link Here
|
868 |
} |
874 |
} |
869 |
} |
875 |
} |
870 |
); |
876 |
); |
|
|
877 |
|
871 |
# item-level hold |
878 |
# item-level hold |
872 |
my $hold_2 = $builder->build_object( |
879 |
my $hold_2 = $builder->build_object( |
873 |
{ |
880 |
{ |
Lines 880-916
subtest 'pickup_locations() tests' => sub {
Link Here
|
880 |
} |
887 |
} |
881 |
); |
888 |
); |
882 |
|
889 |
|
883 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" |
890 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" . $hold_1->id . "/pickup_locations" ) |
884 |
. $hold_1->id |
891 |
->json_is( [ $libraries[1], $libraries[2] ] ); |
885 |
. "/pickup_locations" ) |
|
|
886 |
->json_is( [ $library_2_api, $library_3_api ] ); |
887 |
|
892 |
|
888 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" |
893 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" . $hold_2->id . "/pickup_locations" ) |
889 |
. $hold_2->id |
894 |
->json_is( [ $libraries[0], $libraries[1] ] ); |
890 |
. "/pickup_locations" ) |
|
|
891 |
->json_is( [ $library_1_api, $library_2_api ] ); |
892 |
|
895 |
|
893 |
# filtering works! |
896 |
# filtering works! |
894 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" |
897 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" |
895 |
. $hold_2->id |
898 |
. $hold_2->id |
896 |
. '/pickup_locations?q={"marc_org_code": { "-like": "A%" }}' ) |
899 |
. '/pickup_locations?q={"marc_org_code": { "-like": "A%" }}' )->json_is( [ $libraries[0] ] ); |
897 |
->json_is( [ $library_1_api ] ); |
|
|
898 |
|
900 |
|
899 |
t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); |
901 |
t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 ); |
900 |
|
902 |
|
901 |
my $library_4 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 0, marcorgcode => 'X' } }); |
903 |
# biblio-level mock doesn't include libraries[1] and $libraries[2] as valid pickup location |
902 |
my $library_5 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1, marcorgcode => 'Y' } }); |
904 |
$_->{needs_override} = Mojo::JSON->true for @libraries; |
903 |
|
905 |
$libraries[1]->{needs_override} = Mojo::JSON->false; |
904 |
my $library_5_api = $library_5->to_api(); |
906 |
$libraries[2]->{needs_override} = Mojo::JSON->false; |
905 |
$library_5_api->{needs_override} = Mojo::JSON->true; |
|
|
906 |
|
907 |
|
907 |
# bibli-level mock doesn't include library_1 as valid pickup location |
908 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" . $hold_1->id . "/pickup_locations?_order_by=marc_org_code" ) |
908 |
$library_1_api->{needs_override} = Mojo::JSON->true; |
909 |
->json_is( [ @libraries[ 0 .. 19 ] ] ); |
909 |
|
910 |
|
910 |
$t->get_ok( "//$userid:$password@/api/v1/holds/" |
911 |
# Library "Z" is not listed |
911 |
. $hold_1->id |
912 |
$t->get_ok( |
912 |
. "/pickup_locations?_order_by=marc_org_code" ) |
913 |
"//$userid:$password@/api/v1/holds/" . $hold_1->id . "/pickup_locations?_order_by=marc_org_code&_page=2" ) |
913 |
->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] ); |
914 |
->json_is( [ @libraries[ 20 .. 24 ] ] ); |
914 |
|
915 |
|
915 |
$schema->storage->txn_rollback; |
916 |
$schema->storage->txn_rollback; |
916 |
}; |
917 |
}; |
917 |
- |
|
|