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

(-)a/t/db_dependent/api/v1/holds.t (-2 / +77 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 5;
21
use Test::Mojo;
21
use Test::Mojo;
22
use t::lib::TestBuilder;
22
use t::lib::TestBuilder;
23
use t::lib::Mocks;
23
use t::lib::Mocks;
Lines 328-333 subtest 'Reserves with itemtype' => sub { Link Here
328
328
329
$schema->storage->txn_rollback;
329
$schema->storage->txn_rollback;
330
330
331
subtest 'suspend and resume tests' => sub {
332
333
    plan tests => 20;
334
335
    $schema->storage->txn_begin;
336
337
    my $password = 'AbcdEFG123';
338
339
    my $patron = $builder->build_object(
340
        { class => 'Koha::Patrons', value => { userid => 'tomasito', flags => 1 } } );
341
    $patron->set_password($password);
342
    my $userid = $patron->userid;
343
344
    # Disable logging
345
    t::lib::Mocks::mock_preference( 'HoldsLog',      0 );
346
    t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
347
348
    my $hold = $builder->build_object(
349
        {   class => 'Koha::Holds',
350
            value => { suspend => 0, suspend_until => undef, waitingdate => undef }
351
        }
352
    );
353
354
    ok( !$hold->is_suspended, 'Hold is not suspended' );
355
    $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
356
        ->status_is( 201, 'Hold suspension created' );
357
358
    $hold->discard_changes;    # refresh object
359
360
    ok( $hold->is_suspended, 'Hold is suspended' );
361
    $t->json_is(
362
        '/expiration_date',
363
        output_pref(
364
            {   dt         => dt_from_string( $hold->suspend_until ),
365
                dateformat => 'rfc3339',
366
                dateonly   => 1
367
            }
368
        )
369
    );
370
371
    $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
372
      ->status_is( 204, "Correct status when deleting a resource" )
373
      ->json_is( undef );
374
375
    # Pass a an expiration date for the suspension
376
    my $date = dt_from_string()->add( days => 5 );
377
    $t->post_ok(
378
              "//$userid:$password@/api/v1/holds/"
379
            . $hold->id
380
            . "/suspension" => json => {
381
            expiration_date =>
382
                output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } )
383
            }
384
    )->status_is( 201, 'Hold suspension created' )
385
        ->json_is( '/expiration_date',
386
        output_pref( { dt => $date, dateformat => 'rfc3339', dateonly => 1 } ) );
387
388
    $t->delete_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
389
      ->status_is( 204, "Correct status when deleting a resource" )
390
      ->json_is( undef );
391
392
    $hold->set_waiting->discard_changes;
393
394
    $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
395
      ->status_is( 400, 'Cannot suspend waiting hold' )
396
      ->json_is( '/error', 'Found hold cannot be suspended. Status=W' );
397
398
    $hold->set_waiting(1)->discard_changes;
399
400
    $t->post_ok( "//$userid:$password@/api/v1/holds/" . $hold->id . "/suspension" )
401
      ->status_is( 400, 'Cannot suspend waiting hold' )
402
      ->json_is( '/error', 'Found hold cannot be suspended. Status=T' );
403
404
    $schema->storage->txn_rollback;
405
};
406
331
sub create_biblio {
407
sub create_biblio {
332
    my ($title) = @_;
408
    my ($title) = @_;
333
409
334
- 

Return to bug 22206