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

(-)a/Koha/REST/V1/Holds.pm (-5 / +7 lines)
Lines 185-191 sub add { Link Here
185
185
186
        # AddReserve expects date to be in syspref format
186
        # AddReserve expects date to be in syspref format
187
        if ($expiration_date) {
187
        if ($expiration_date) {
188
            $expiration_date = output_pref( dt_from_string( $expiration_date, 'rfc3339' ) );
188
            $expiration_date = output_pref( { dt => dt_from_string($expiration_date, 'iso'), dateformat => 'iso', dateonly => 1 } );
189
        }
189
        }
190
190
191
        my $hold_id = C4::Reserves::AddReserve(
191
        my $hold_id = C4::Reserves::AddReserve(
Lines 286-292 sub edit { Link Here
286
            reserve_id    => $hold_id,
286
            reserve_id    => $hold_id,
287
            branchcode    => $pickup_library_id,
287
            branchcode    => $pickup_library_id,
288
            rank          => $priority,
288
            rank          => $priority,
289
            suspend_until => $suspended_until ? output_pref(dt_from_string($suspended_until, 'rfc3339')) : '',
289
            suspend_until => $suspended_until
290
              ? output_pref({ dt => dt_from_string($suspended_until, 'iso'), dateformat => 'iso', dateonly => 1 })
291
              : '',
290
            itemnumber    => $hold->itemnumber
292
            itemnumber    => $hold->itemnumber
291
        };
293
        };
292
294
Lines 351-365 sub suspend { Link Here
351
    }
353
    }
352
354
353
    return try {
355
    return try {
354
        my $date = ($end_date) ? dt_from_string( $end_date, 'rfc3339' ) : undef;
356
        my $date = ($end_date) ? dt_from_string( $end_date, 'iso' ) : undef;
355
        $hold->suspend_hold($date);
357
        $hold->suspend_hold($date);
356
        $hold->discard_changes;
358
        $hold->discard_changes;
357
        $c->res->headers->location( $c->req->url->to_string );
359
        $c->res->headers->location( $c->req->url->to_string );
358
        my $suspend_end_date;
360
        my $suspend_end_date;
359
        if ($hold->suspend_until) {
361
        if ($hold->suspend_until) {
360
            $suspend_end_date = output_pref({
362
            $suspend_end_date = output_pref({
361
                dt         => dt_from_string( $hold->suspend_until ),
363
                dt         => dt_from_string( $hold->suspend_until, 'iso' ),
362
                dateformat => 'rfc3339',
364
                dateformat => 'iso',
363
                dateonly   => 1
365
                dateonly   => 1
364
                }
366
                }
365
            );
367
            );
(-)a/t/db_dependent/api/v1/holds.t (-11 / +10 lines)
Lines 159-169 my $post_data = { Link Here
159
    biblio_id         => $biblio_1->biblionumber,
159
    biblio_id         => $biblio_1->biblionumber,
160
    item_id           => $item_1->itemnumber,
160
    item_id           => $item_1->itemnumber,
161
    pickup_library_id => $branchcode,
161
    pickup_library_id => $branchcode,
162
    expiration_date   => output_pref( { dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 } ),
162
    expiration_date   => output_pref( { dt => $expiration_date, dateformat => 'iso', dateonly => 1 } ),
163
};
163
};
164
my $patch_data = {
164
my $patch_data = {
165
    priority        => 2,
165
    priority        => 2,
166
    suspended_until => output_pref( { dt => $suspended_until, dateformat => 'rfc3339' } ),
166
    suspended_until => output_pref( { dt => $suspended_until, dateformat => 'iso', dateonly => 1 } ),
167
};
167
};
168
168
169
subtest "Test endpoints without authentication" => sub {
169
subtest "Test endpoints without authentication" => sub {
Lines 254-260 subtest "Test endpoints with permission" => sub { Link Here
254
    $t->get_ok( "//$userid_1:$password@/api/v1/holds?patron_id=" . $patron_1->borrowernumber )
254
    $t->get_ok( "//$userid_1:$password@/api/v1/holds?patron_id=" . $patron_1->borrowernumber )
255
      ->status_is(200)
255
      ->status_is(200)
256
      ->json_is('/0/hold_id', $reserve_id)
256
      ->json_is('/0/hold_id', $reserve_id)
257
      ->json_is('/0/expiration_date', output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 }))
257
      ->json_is('/0/expiration_date', output_pref({ dt => $expiration_date, dateformat => 'iso', dateonly => 1 }))
258
      ->json_is('/0/pickup_library_id', $branchcode);
258
      ->json_is('/0/pickup_library_id', $branchcode);
259
259
260
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
260
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
Lines 329-336 subtest 'test AllowHoldDateInFuture' => sub { Link Here
329
        biblio_id         => $biblio_1->biblionumber,
329
        biblio_id         => $biblio_1->biblionumber,
330
        item_id           => $item_1->itemnumber,
330
        item_id           => $item_1->itemnumber,
331
        pickup_library_id => $branchcode,
331
        pickup_library_id => $branchcode,
332
        expiration_date   => output_pref( { dt => $expiration_date,  dateformat => 'rfc3339', dateonly => 1 } ),
332
        expiration_date   => output_pref( { dt => $expiration_date,  dateformat => 'iso', dateonly => 1 } ),
333
        hold_date         => output_pref( { dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 } ),
333
        hold_date         => output_pref( { dt => $future_hold_date, dateformat => 'iso', dateonly => 1 } ),
334
    };
334
    };
335
335
336
    t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 );
336
    t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 );
Lines 349-355 subtest 'test AllowHoldDateInFuture' => sub { Link Here
349
349
350
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
350
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
351
      ->status_is(201)
351
      ->status_is(201)
352
      ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }));
352
      ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'iso', dateonly => 1 }));
353
};
353
};
354
354
355
$schema->storage->txn_rollback;
355
$schema->storage->txn_rollback;
Lines 486-492 subtest 'suspend and resume tests' => sub { Link Here
486
486
487
    my $end_date = output_pref({
487
    my $end_date = output_pref({
488
      dt         => dt_from_string( undef ),
488
      dt         => dt_from_string( undef ),
489
      dateformat => 'rfc3339',
489
      dateformat => 'iso',
490
      dateonly   => 1
490
      dateonly   => 1
491
    });
491
    });
492
492
Lines 499-505 subtest 'suspend and resume tests' => sub { Link Here
499
      '/end_date',
499
      '/end_date',
500
      output_pref({
500
      output_pref({
501
        dt         => dt_from_string( $hold->suspend_until ),
501
        dt         => dt_from_string( $hold->suspend_until ),
502
        dateformat => 'rfc3339',
502
        dateformat => 'iso',
503
        dateonly   => 1
503
        dateonly   => 1
504
      }),
504
      }),
505
      'Hold suspension has correct end date'
505
      'Hold suspension has correct end date'
Lines 516-526 subtest 'suspend and resume tests' => sub { Link Here
516
            . $hold->id
516
            . $hold->id
517
            . "/suspension" => json => {
517
            . "/suspension" => json => {
518
            end_date =>
518
            end_date =>
519
                output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } )
519
                output_pref( { dt => $date, dateformat => 'iso', dateonly => 1 } )
520
            }
520
            }
521
    )->status_is( 201, 'Hold suspension created' )
521
    )->status_is( 201, 'Hold suspension created' )
522
        ->json_is( '/end_date',
522
        ->json_is( '/end_date',
523
        output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) )
523
        output_pref( { dt => $date, dateformat => 'iso', dateonly => 1 } ) )
524
        ->header_is( Location => "/api/v1/holds/" . $hold->id . "/suspension", 'The Location header is set' );
524
        ->header_is( Location => "/api/v1/holds/" . $hold->id . "/suspension", 'The Location header is set' );
525
525
526
    $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
526
    $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
527
- 

Return to bug 24850