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

(-)a/t/db_dependent/api/v1/holds.t (-5 / +75 lines)
Lines 1055-1071 subtest 'add() tests' => sub { Link Here
1055
    $schema->storage->txn_rollback;
1055
    $schema->storage->txn_rollback;
1056
};
1056
};
1057
1057
1058
1059
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
1058
subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub {
1060
1059
1061
    plan tests => 4;
1060
    plan tests => 16;
1062
1061
1063
    $schema->storage->txn_begin;
1062
    $schema->storage->txn_begin;
1064
1063
1065
    my $password = 'AbcdEFG123';
1064
    my $password = 'AbcdEFG123';
1066
1065
1067
    my $library_1   =  $builder->build_object({ class => 'Koha::Libraries' });
1066
    my $library_1 = $builder->build_object({ class => 'Koha::Libraries' });
1068
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1067
    my $library_2 = $builder->build_object({ class => 'Koha::Libraries' });
1068
    my $library_3 = $builder->build_object({ class => 'Koha::Libraries' });
1069
1069
1070
    my $patron = $builder->build_object(
1070
    my $patron = $builder->build_object(
1071
        { class => 'Koha::Patrons', value => { flags => 0 } } );
1071
        { class => 'Koha::Patrons', value => { flags => 0 } } );
Lines 1086-1092 subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { Link Here
1086
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1086
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
1087
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1087
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
1088
1088
1089
    my $libraries_query = { branchcode => [ $library_1->branchcode, $library_2->branchcode ] };
1090
1091
    my $mocked_biblio = Test::MockModule->new('Koha::Biblio');
1092
    $mocked_biblio->mock( 'pickup_locations', sub {
1093
        return Koha::Libraries->search($libraries_query);
1094
    });
1095
1096
    my $mocked_item = Test::MockModule->new('Koha::Item');
1097
    $mocked_item->mock( 'pickup_locations', sub {
1098
        return Koha::Libraries->search($libraries_query);
1099
    });
1100
1089
    my $biblio = $builder->build_sample_biblio;
1101
    my $biblio = $builder->build_sample_biblio;
1102
    my $item   = $builder->build_sample_item(
1103
        {
1104
            biblionumber => $biblio->biblionumber,
1105
            library      => $library_1->branchcode
1106
        }
1107
    );
1108
1109
    # biblio-level hold
1090
    my $hold = Koha::Holds->find(
1110
    my $hold = Koha::Holds->find(
1091
        AddReserve(
1111
        AddReserve(
1092
            {
1112
            {
Lines 1094-1106 subtest 'PUT /holds/{hold_id}/pickup_location tests' => sub { Link Here
1094
                borrowernumber => $patron->borrowernumber,
1114
                borrowernumber => $patron->borrowernumber,
1095
                biblionumber   => $biblio->biblionumber,
1115
                biblionumber   => $biblio->biblionumber,
1096
                priority       => 1,
1116
                priority       => 1,
1117
                itemnumber     => undef,
1118
            }
1119
        )
1120
    );
1121
1122
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1123
          . $hold->id
1124
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
1125
      ->status_is(200)
1126
      ->json_is({ pickup_library_id => $library_2->branchcode });
1127
1128
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1129
1130
    $libraries_query = { branchcode => $library_1->branchcode };
1131
1132
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1133
          . $hold->id
1134
          . "/pickup_location" => json => { pickup_library_id => $library_3->branchcode } )
1135
      ->status_is(400)
1136
      ->json_is({ error => '[The supplied pickup location is not valid]' });
1137
1138
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library unchanged' );
1139
1140
    # item-level hold
1141
    $hold = Koha::Holds->find(
1142
        AddReserve(
1143
            {
1144
                branchcode     => $library_1->branchcode,
1145
                borrowernumber => $patron->borrowernumber,
1146
                biblionumber   => $biblio->biblionumber,
1147
                priority       => 1,
1148
                itemnumber     => $item->itemnumber,
1097
            }
1149
            }
1098
        )
1150
        )
1099
    );
1151
    );
1100
1152
1153
    $libraries_query = { branchcode => $library_1->branchcode };
1154
1155
    # Attempt to use an invalid pickup locations ends in 400
1156
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1157
          . $hold->id
1158
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
1159
      ->status_is(400)
1160
      ->json_is({ error => '[The supplied pickup location is not valid]' });
1161
1162
    is( $hold->discard_changes->branchcode->branchcode, $library_1->branchcode, 'pickup library unchanged' );
1163
1164
    $libraries_query = {
1165
        branchcode => {
1166
            '-in' => [ $library_1->branchcode, $library_2->branchcode ]
1167
        }
1168
    };
1169
1101
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1170
    $t->put_ok( "//$userid:$password@/api/v1/holds/"
1102
          . $hold->id
1171
          . $hold->id
1103
          . "/pickup_location" => json => $library_2->branchcode )->status_is(200)->json_is($library_2->branchcode);
1172
          . "/pickup_location" => json => { pickup_library_id => $library_2->branchcode } )
1173
      ->status_is(200)
1174
      ->json_is({ pickup_library_id => $library_2->branchcode });
1104
1175
1105
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1176
    is( $hold->discard_changes->branchcode->branchcode, $library_2->branchcode, 'pickup library adjusted correctly' );
1106
1177
1107
- 

Return to bug 18729