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

(-)a/t/db_dependent/api/v1/holds.t (-8 / +35 lines)
Lines 687-699 subtest 'add() tests (maxreserves behaviour)' => sub { Link Here
687
687
688
subtest 'pickup_locations() tests' => sub {
688
subtest 'pickup_locations() tests' => sub {
689
689
690
    plan tests => 9;
690
    plan tests => 12;
691
691
692
    $schema->storage->txn_begin;
692
    $schema->storage->txn_begin;
693
693
694
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'A' } });
694
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
695
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'B' } });
695
696
    my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'C' } });
696
    # Small trick to ease testing
697
    Koha::Libraries->search->update({ pickup_location => 0 });
698
699
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'A', pickup_location => 1 } });
700
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'B', pickup_location => 1 } });
701
    my $library_3 = $builder->build_object({ class => 'Koha::Libraries', value => { marcorgcode => 'C', pickup_location => 1 } });
702
703
    my $library_1_api = $library_1->to_api();
704
    my $library_2_api = $library_2->to_api();
705
    my $library_3_api = $library_3->to_api();
706
707
    $library_1_api->{needs_override} = Mojo::JSON->false;
708
    $library_2_api->{needs_override} = Mojo::JSON->false;
709
    $library_3_api->{needs_override} = Mojo::JSON->false;
697
710
698
    my $patron = $builder->build_object(
711
    my $patron = $builder->build_object(
699
        {
712
        {
Lines 790-808 subtest 'pickup_locations() tests' => sub { Link Here
790
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
803
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
791
          . $hold_1->id
804
          . $hold_1->id
792
          . "/pickup_locations" )
805
          . "/pickup_locations" )
793
      ->json_is( [ $library_2->to_api, $library_3->to_api ] );
806
      ->json_is( [ $library_2_api, $library_3_api ] );
794
807
795
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
808
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
796
          . $hold_2->id
809
          . $hold_2->id
797
          . "/pickup_locations" )
810
          . "/pickup_locations" )
798
      ->json_is( [ $library_1->to_api, $library_2->to_api ] );
811
      ->json_is( [ $library_1_api, $library_2_api ] );
799
812
800
    # filtering works!
813
    # filtering works!
801
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
814
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
802
          . $hold_2->id
815
          . $hold_2->id
803
          . '/pickup_locations?q={"marc_org_code": { "-like": "A%" }}' )
816
          . '/pickup_locations?q={"marc_org_code": { "-like": "A%" }}' )
804
      ->json_is( [ $library_1->to_api ] );
817
      ->json_is( [ $library_1_api ] );
818
819
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
820
821
    my $library_4 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 0, marcorgcode => 'X' } });
822
    my $library_5 = $builder->build_object({ class => 'Koha::Libraries', value => { pickup_location => 1, marcorgcode => 'Y' } });
823
824
    my $library_5_api = $library_5->to_api();
825
    $library_5_api->{needs_override} = Mojo::JSON->true;
805
826
827
    # bibli-level mock doesn't include library_1 as valid pickup location
828
    $library_1_api->{needs_override} = Mojo::JSON->true;
829
830
    $t->get_ok( "//$userid:$password@/api/v1/holds/"
831
          . $hold_1->id
832
          . "/pickup_locations?_order_by=marc_org_code" )
833
      ->json_is( [ $library_1_api, $library_2_api, $library_3_api, $library_5_api ] );
806
834
807
    $schema->storage->txn_rollback;
835
    $schema->storage->txn_rollback;
808
};
836
};
809
- 

Return to bug 27894