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

(-)a/t/db_dependent/api/v1/holds.t (-25 / +52 lines)
Lines 354-401 subtest 'test AllowHoldDateInFuture' => sub { Link Here
354
      ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }));
354
      ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }));
355
};
355
};
356
356
357
subtest 'test AllowHoldPolicyOverride' => sub {
357
$schema->storage->txn_rollback;
358
358
359
    plan tests => 7;
359
subtest 'x-koha-override and AllowHoldPolicyOverride tests' => sub {
360
360
361
    $dbh->do('DELETE FROM reserves');
361
    plan tests => 8;
362
362
363
    Koha::CirculationRules->set_rules(
363
    $schema->storage->txn_begin;
364
365
    my $patron = $builder->build_object(
364
        {
366
        {
365
            itemtype   => undef,
367
            class => 'Koha::Patrons',
366
            branchcode => undef,
368
            value => { flags => 1 }
367
            rules      => {
368
                holdallowed => 'from_home_library'
369
            }
370
        }
369
        }
371
    );
370
    );
371
    my $password = 'thePassword123';
372
    $patron->set_password( { password => $password, skip_validation => 1 } );
373
    $patron->discard_changes;
374
    my $userid = $patron->userid;
372
375
373
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
376
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
374
377
375
    # Make sure pickup location checks doesn't get in the middle
378
    # Make sure pickup location checks doesn't get in the middle
376
    my $mock_biblio = Test::MockModule->new('Koha::Biblio');
379
    my $mock_biblio = Test::MockModule->new('Koha::Biblio');
377
    $mock_biblio->mock( 'pickup_locations', sub { return Koha::Libraries->search; });
380
    $mock_biblio->mock( 'pickup_locations',
378
    my $mock_item   = Test::MockModule->new('Koha::Item');
381
        sub { return Koha::Libraries->search; } );
379
    $mock_item->mock( 'pickup_locations', sub { return Koha::Libraries->search });
382
    my $mock_item = Test::MockModule->new('Koha::Item');
383
    $mock_item->mock( 'pickup_locations',
384
        sub { return Koha::Libraries->search } );
385
386
    my $can_item_be_reserved_result;
387
    my $mock_reserves = Test::MockModule->new('C4::Reserves');
388
    $mock_reserves->mock(
389
        'CanItemBeReserved',
390
        sub {
391
            return $can_item_be_reserved_result;
392
        }
393
    );
380
394
381
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
395
    my $item = $builder->build_sample_item;
396
397
    my $post_data = {
398
        item_id           => $item->id,
399
        biblio_id         => $item->biblionumber,
400
        patron_id         => $patron->id,
401
        pickup_library_id => $patron->branchcode,
402
    };
403
404
    $can_item_be_reserved_result = { status => 'ageRestricted' };
405
406
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
382
      ->status_is(403)
407
      ->status_is(403)
383
      ->json_has('/error');
408
      ->json_is( '/error' => "Hold cannot be placed. Reason: ageRestricted" );
384
409
385
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
410
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
386
411
387
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
412
    $can_item_be_reserved_result = { status => 'pickupNotInHoldGroup' };
388
      ->status_is(403);
389
413
390
    $t->post_ok(
414
    $t->post_ok( "//$userid:$password@/api/v1/holds" => json => $post_data )
391
        "//$userid_3:$password@/api/v1/holds" => {
415
      ->status_is(403)
392
            'x-koha-override' =>
416
      ->json_is(
393
              encode_json( { AllowHoldPolicyOverride => Mojo::JSON->true } )
417
        '/error' => "Hold cannot be placed. Reason: pickupNotInHoldGroup" );
394
        } => json => $post_data
395
    )->status_is(201);
396
};
397
418
398
$schema->storage->txn_rollback;
419
    $can_item_be_reserved_result = { status => 'OK' };
420
421
    $t->post_ok( "//$userid:$password@/api/v1/holds" =>
422
          { 'x-koha-override' => 'any' } => json => $post_data )
423
      ->status_is(201);
424
425
    $schema->storage->txn_rollback;
426
};
399
427
400
subtest 'suspend and resume tests' => sub {
428
subtest 'suspend and resume tests' => sub {
401
429
402
- 

Return to bug 27797