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

(-)a/t/db_dependent/api/v1/holds.t (-4 / +82 lines)
Lines 790-802 subtest 'pickup_locations() tests' => sub { Link Here
790
790
791
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
791
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
792
792
793
    plan tests => 4;
793
    plan tests => 16;
794
794
795
    $schema->storage->txn_begin;
795
    $schema->storage->txn_begin;
796
796
797
    my $password = 'AbcdEFG123';
797
    my $password = 'AbcdEFG123';
798
798
799
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
799
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
800
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
800
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
801
801
802
    my $patron = $builder->build_object(
802
    my $patron = $builder->build_object(
Lines 818-824 subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { Link Here
818
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
818
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
819
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
819
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
820
820
821
    my $libraries_rs = Koha::Libraries->search(
822
        {
823
            branchcode => {
824
                '-in' => [ $library_1->branchcode, $library_2->branchcode ]
825
            }
826
        }
827
    );
828
829
    my $mocked_biblio = Test::MockModule->new('Koha::Biblio');
830
    $mocked_biblio->mock( 'pickup_locations', sub {
831
        return $libraries_rs;
832
    });
833
834
    my $mocked_item = Test::MockModule->new('Koha::Item');
835
    $mocked_item->mock( 'pickup_locations', sub {
836
        return $libraries_rs;
837
    });
838
821
    my $biblio = $builder->build_sample_biblio;
839
    my $biblio = $builder->build_sample_biblio;
840
    my $item   = $builder->build_sample_item(
841
        {
842
            biblionumber => $biblio->biblionumber,
843
            library      => $library_1->branchcode
844
        }
845
    );
846
847
    # biblio-level hold
822
    my $hold = Koha::Holds->find(
848
    my $hold = Koha::Holds->find(
823
        AddReserve(
849
        AddReserve(
824
            {
850
            {
Lines 826-838 subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { Link Here
826
                borrowernumber => $patron->borrowernumber,
852
                borrowernumber => $patron->borrowernumber,
827
                biblionumber   => $biblio->biblionumber,
853
                biblionumber   => $biblio->biblionumber,
828
                priority       => 1,
854
                priority       => 1,
855
                itemnumber     => undef,
829
            }
856
            }
830
        )
857
        )
831
    );
858
    );
832
859
833
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
860
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
834
          . $hold->id
861
          . $hold->id
835
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
862
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
863
      ->status_is(200)
864
      ->json_is({ pickup_library_id => $library_2->branchcode });
865
866
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
867
868
    $libraries_rs = Koha::Libraries->search({ branchcode => $library_1->branchcode });
869
870
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
871
          . $hold->id
872
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
873
      ->status_is(400)
874
      ->json_is({ error => 'Invalid pickup location passed' });
875
876
    is( $hold->discard_changes->branchcode->branchcode, $library_1->branchcode, 'pickup library unchanged' );
877
878
    # item-level hold
879
    $hold = Koha::Holds->find(
880
        AddReserve(
881
            {
882
                branchcode     => $library_1->branchcode,
883
                borrowernumber => $patron->borrowernumber,
884
                biblionumber   => $biblio->biblionumber,
885
                priority       => 1,
886
                itemnumber     => $item->itemnumber,
887
            }
888
        )
889
    );
890
891
    $libraries_rs = Koha::Libraries->search({ branchcode => $library_1->branchcode });
892
893
    # Attempt to use an invalid pickup locations ends in 400
894
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
895
          . $hold->id
896
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
897
      ->status_is(400)
898
      ->json_is({ error => 'Invalid pickup location passed' });
899
900
    is( $hold->discard_changes->branchcode->branchcode, $library_1->branchcode, 'pickup library unchanged' );
901
902
    $libraries_rs = Koha::Libraries->search(
903
        {
904
            branchcode => {
905
                '-in' => [ $library_1->branchcode, $library_2->branchcode ]
906
            }
907
        }
908
    );
909
910
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
911
          . $hold->id
912
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
913
      ->status_is(200)
914
      ->json_is({ pickup_library_id => $library_2->branchcode });
836
915
837
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
916
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
838
917
839
- 

Return to bug 18729