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

(-)a/Koha/REST/V1/Holds.pm (-8 / +5 lines)
Lines 243-261 sub edit { Link Here
243
243
244
    my $body = $c->req->json;
244
    my $body = $c->req->json;
245
245
246
    my $pickup_library_id = $body->{pickup_library_id};
246
    my $pickup_library_id = $body->{pickup_library_id} // $hold->branchcode;
247
    my $priority          = $body->{priority};
247
    my $priority          = $body->{priority} // $hold->priority;
248
    my $suspended_until   = $body->{suspended_until};
248
    # suspended_until can also be set to undef
249
249
    my $suspended_until   = exists $body->{suspended_until} ? $body->{suspended_until} : $hold->suspend_until;
250
    if ($suspended_until) {
251
        $suspended_until = output_pref(dt_from_string($suspended_until, 'rfc3339'));
252
    }
253
250
254
    my $params = {
251
    my $params = {
255
        reserve_id    => $hold_id,
252
        reserve_id    => $hold_id,
256
        branchcode    => $pickup_library_id,
253
        branchcode    => $pickup_library_id,
257
        rank          => $priority,
254
        rank          => $priority,
258
        suspend_until => $suspended_until,
255
        suspend_until => $suspended_until ? output_pref(dt_from_string($suspended_until, 'rfc3339')) : '',
259
        itemnumber    => $hold->itemnumber
256
        itemnumber    => $hold->itemnumber
260
    };
257
    };
261
258
(-)a/t/db_dependent/api/v1/holds.t (-4 / +25 lines)
Lines 47-52 my $t = Test::Mojo->new('Koha::REST::V1'); Link Here
47
47
48
my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
48
my $categorycode = $builder->build({ source => 'Category' })->{categorycode};
49
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
49
my $branchcode = $builder->build({ source => 'Branch' })->{branchcode};
50
my $branchcode2 = $builder->build({ source => 'Branch' })->{branchcode};
50
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
51
my $itemtype = $builder->build({ source => 'Itemtype' })->{itemtype};
51
52
52
# Generic password for everyone
53
# Generic password for everyone
Lines 198-204 subtest "Test endpoints without permission" => sub { Link Here
198
199
199
subtest "Test endpoints with permission" => sub {
200
subtest "Test endpoints with permission" => sub {
200
201
201
    plan tests => 44;
202
    plan tests => 57;
202
203
203
    $t->get_ok( "//$userid_1:$password@/api/v1/holds" )
204
    $t->get_ok( "//$userid_1:$password@/api/v1/holds" )
204
      ->status_is(200)
205
      ->status_is(200)
Lines 211-221 subtest "Test endpoints with permission" => sub { Link Here
211
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
212
      ->json_is('/0/patron_id', $patron_2->borrowernumber)
212
      ->json_hasnt('/1');
213
      ->json_hasnt('/1');
213
214
215
    # While suspended_until is date-time, it's always set to midnight.
216
    my $expected_suspended_until = $suspended_until->strftime('%FT00:00:00%z');
217
    substr($expected_suspended_until, -2, 0, ':');
218
214
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
219
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => $put_data )
215
      ->status_is(200)
220
      ->status_is(200)
216
      ->json_is( '/hold_id', $reserve_id )
221
      ->json_is( '/hold_id', $reserve_id )
217
      ->json_is( '/suspended_until', output_pref({ dt => $suspended_until, dateformat => 'rfc3339' }) )
222
      ->json_is( '/suspended_until', $expected_suspended_until )
218
      ->json_is( '/priority', 2 );
223
      ->json_is( '/priority', 2 )
224
      ->json_is( '/pickup_library_id', $branchcode );
225
226
    # Change only pickup library, everything else should remain
227
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => { pickup_library_id => $branchcode2 } )
228
      ->status_is(200)
229
      ->json_is( '/hold_id', $reserve_id )
230
      ->json_is( '/suspended_until', $expected_suspended_until )
231
      ->json_is( '/priority', 2 )
232
      ->json_is( '/pickup_library_id', $branchcode2 );
233
234
    # Reset suspended_until, everything else should remain
235
    $t->put_ok( "//$userid_1:$password@/api/v1/holds/$reserve_id" => json => { suspended_until => undef } )
236
      ->status_is(200)
237
      ->json_is( '/hold_id', $reserve_id )
238
      ->json_is( '/suspended_until', undef )
239
      ->json_is( '/priority', 2 )
240
      ->json_is( '/pickup_library_id', $branchcode2 );
219
241
220
    $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" )
242
    $t->delete_ok( "//$userid_3:$password@/api/v1/holds/$reserve_id" )
221
      ->status_is(200);
243
      ->status_is(200);
222
- 

Return to bug 24680