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

(-)a/Koha/REST/V1/Holds.pm (-1 / +8 lines)
Lines 84-90 sub add { Link Here
84
        my $item_type         = $body->{item_type};
84
        my $item_type         = $body->{item_type};
85
        my $expiration_date   = $body->{expiration_date};
85
        my $expiration_date   = $body->{expiration_date};
86
        my $notes             = $body->{notes};
86
        my $notes             = $body->{notes};
87
        my $hold_date         = C4::Context->preference( 'AllowHoldDateInFuture' )?$body->{hold_date}:undef;
87
        my $hold_date         = $body->{hold_date};
88
89
        if(!C4::Context->preference( 'AllowHoldDateInFuture' ) && $hold_date) {
90
            return $c->render(
91
                status  => 400,
92
                openapi => { error => "Hold date in future not allowed" }
93
            );
94
        }
88
95
89
        if ( $item_id and $biblio_id ) {
96
        if ( $item_id and $biblio_id ) {
90
97
(-)a/t/db_dependent/api/v1/holds.t (-3 / +64 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 6;
20
use Test::More tests => 8;
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 34-39 use Koha::DateUtils; Link Here
34
use Koha::Biblios;
34
use Koha::Biblios;
35
use Koha::Biblioitems;
35
use Koha::Biblioitems;
36
use Koha::Items;
36
use Koha::Items;
37
use Koha::CirculationRules;
37
38
38
my $schema  = Koha::Database->new->schema;
39
my $schema  = Koha::Database->new->schema;
39
my $builder = t::lib::TestBuilder->new();
40
my $builder = t::lib::TestBuilder->new();
Lines 267-272 subtest 'Reserves with itemtype' => sub { Link Here
267
      ->json_is('/0/item_type', $itemtype);
268
      ->json_is('/0/item_type', $itemtype);
268
};
269
};
269
270
271
272
subtest 'test AllowHoldDateInFuture' => sub {
273
274
    plan tests => 6;
275
276
    $dbh->do('DELETE FROM reserves');
277
278
    my $future_hold_date = DateTime->now->add(days => 10)->truncate( to => 'day' );
279
280
    my $post_data = {
281
        patron_id => int($patron_1->borrowernumber),
282
        biblio_id => int($biblio_1->biblionumber),
283
        item_id => int($item_1->itemnumber),
284
        pickup_library_id => $branchcode,
285
        expiration_date => output_pref({ dt => $expiration_date, dateformat => 'rfc3339', dateonly => 1 }),
286
        hold_date => output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }),
287
        priority => 2,
288
    };
289
290
    t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 );
291
292
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
293
      ->status_is(400)
294
      ->json_has('/error');
295
296
    t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 1 );
297
298
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
299
      ->status_is(201)
300
      ->json_is('/hold_date', output_pref({ dt => $future_hold_date, dateformat => 'rfc3339', dateonly => 1 }));
301
};
302
303
subtest 'test AllowHoldPolicyOverride' => sub {
304
305
    plan tests => 5;
306
307
    $dbh->do('DELETE FROM reserves');
308
309
    Koha::CirculationRules->set_rules(
310
        {
311
            categorycode => undef,
312
            itemtype     => undef,
313
            branchcode   => undef,
314
            rules        => {
315
                holdallowed              => 1
316
            }
317
        }
318
    );
319
320
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 0 );
321
322
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
323
      ->status_is(403)
324
      ->json_has('/error');
325
326
    t::lib::Mocks::mock_preference( 'AllowHoldPolicyOverride', 1 );
327
328
    $t->post_ok( "//$userid_3:$password@/api/v1/holds" => json => $post_data )
329
      ->status_is(201);
330
};
331
270
$schema->storage->txn_rollback;
332
$schema->storage->txn_rollback;
271
333
272
subtest 'suspend and resume tests' => sub {
334
subtest 'suspend and resume tests' => sub {
Lines 442-445 subtest 'PUT /holds/{hold_id}/priority tests' => sub { Link Here
442
    is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' );
504
    is( $hold_3->discard_changes->priority, 3, 'Priority adjusted correctly' );
443
505
444
    $schema->storage->txn_rollback;
506
    $schema->storage->txn_rollback;
445
};
507
};
446
- 

Return to bug 23710