|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 14; |
20 |
use Test::More tests => 16; |
| 21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
| 22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
| 23 |
use t::lib::TestBuilder; |
23 |
use t::lib::TestBuilder; |
|
Lines 1461-1463
subtest 'delete() tests' => sub {
Link Here
|
| 1461 |
|
1461 |
|
| 1462 |
$schema->storage->txn_rollback; |
1462 |
$schema->storage->txn_rollback; |
| 1463 |
}; |
1463 |
}; |
| 1464 |
- |
1464 |
|
|
|
1465 |
subtest 'PUT /holds/{hold_id}/hold_date tests' => sub { |
| 1466 |
|
| 1467 |
plan tests => 10; |
| 1468 |
|
| 1469 |
$schema->storage->txn_begin; |
| 1470 |
|
| 1471 |
my $password = 'AbcdEFG123'; |
| 1472 |
|
| 1473 |
my $library_1 = $builder->build_object( |
| 1474 |
{ class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1475 |
|
| 1476 |
my $patron = $builder->build_object( |
| 1477 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
| 1478 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 1479 |
my $userid = $patron->userid; |
| 1480 |
$builder->build( |
| 1481 |
{ |
| 1482 |
source => 'UserPermission', |
| 1483 |
value => { |
| 1484 |
borrowernumber => $patron->borrowernumber, |
| 1485 |
module_bit => 6, |
| 1486 |
code => 'place_holds', |
| 1487 |
}, |
| 1488 |
} |
| 1489 |
); |
| 1490 |
|
| 1491 |
# Disable logging |
| 1492 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 1493 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 1494 |
|
| 1495 |
my $biblio = $builder->build_sample_biblio; |
| 1496 |
|
| 1497 |
# biblio-level hold |
| 1498 |
my $hold = Koha::Holds->find( |
| 1499 |
AddReserve( |
| 1500 |
{ |
| 1501 |
branchcode => $library_1->branchcode, |
| 1502 |
borrowernumber => $patron->borrowernumber, |
| 1503 |
biblionumber => $biblio->biblionumber, |
| 1504 |
priority => 1, |
| 1505 |
itemnumber => undef, |
| 1506 |
} |
| 1507 |
) |
| 1508 |
); |
| 1509 |
|
| 1510 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); |
| 1511 |
|
| 1512 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1513 |
. $hold->id |
| 1514 |
. "/hold_date" => json => { hold_date => '2022-01-01' } ) |
| 1515 |
->status_is(403) |
| 1516 |
->json_is({ error => 'Update not allowed' }); |
| 1517 |
|
| 1518 |
|
| 1519 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 1 ); |
| 1520 |
|
| 1521 |
# Attempt to use an invalid pickup locations ends in 400 |
| 1522 |
$t->put_ok( "//$userid:$password@/api/v1/holds/0" |
| 1523 |
. "/hold_date" => json => { hold_date => '2022-01-01' } ) |
| 1524 |
->status_is(404) |
| 1525 |
->json_is({ error => 'Hold not found' }); |
| 1526 |
|
| 1527 |
|
| 1528 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1529 |
. $hold->id |
| 1530 |
. "/hold_date" => json => { hold_date => '2022-01-01' } ) |
| 1531 |
->status_is(200) |
| 1532 |
->json_is({ hold_date => '2022-01-01' }); |
| 1533 |
|
| 1534 |
is( $hold->discard_changes->reservedate, '2022-01-01', 'hold date changed correctly' ); |
| 1535 |
|
| 1536 |
$schema->storage->txn_rollback; |
| 1537 |
}; |
| 1538 |
|
| 1539 |
subtest 'PUT /holds/{hold_id}/expiration_date tests' => sub { |
| 1540 |
|
| 1541 |
plan tests => 7; |
| 1542 |
|
| 1543 |
$schema->storage->txn_begin; |
| 1544 |
|
| 1545 |
my $password = 'AbcdEFG123'; |
| 1546 |
|
| 1547 |
my $library_1 = $builder->build_object( |
| 1548 |
{ class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
| 1549 |
|
| 1550 |
my $patron = $builder->build_object( |
| 1551 |
{ class => 'Koha::Patrons', value => { flags => 0 } } ); |
| 1552 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 1553 |
my $userid = $patron->userid; |
| 1554 |
$builder->build( |
| 1555 |
{ |
| 1556 |
source => 'UserPermission', |
| 1557 |
value => { |
| 1558 |
borrowernumber => $patron->borrowernumber, |
| 1559 |
module_bit => 6, |
| 1560 |
code => 'place_holds', |
| 1561 |
}, |
| 1562 |
} |
| 1563 |
); |
| 1564 |
|
| 1565 |
# Disable logging |
| 1566 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 1567 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 1568 |
|
| 1569 |
my $biblio = $builder->build_sample_biblio; |
| 1570 |
|
| 1571 |
# biblio-level hold |
| 1572 |
my $hold = Koha::Holds->find( |
| 1573 |
AddReserve( |
| 1574 |
{ |
| 1575 |
branchcode => $library_1->branchcode, |
| 1576 |
borrowernumber => $patron->borrowernumber, |
| 1577 |
biblionumber => $biblio->biblionumber, |
| 1578 |
priority => 1, |
| 1579 |
itemnumber => undef, |
| 1580 |
} |
| 1581 |
) |
| 1582 |
); |
| 1583 |
|
| 1584 |
# Attempt to use an invalid pickup locations ends in 400 |
| 1585 |
$t->put_ok( "//$userid:$password@/api/v1/holds/0" |
| 1586 |
. "/expiration_date" => json => { expiration_date => '2022-01-01' } ) |
| 1587 |
->status_is(404) |
| 1588 |
->json_is({ error => 'Hold not found' }); |
| 1589 |
|
| 1590 |
|
| 1591 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
| 1592 |
. $hold->id |
| 1593 |
. "/expiration_date" => json => { expiration_date => '2022-01-01' } ) |
| 1594 |
->status_is(200) |
| 1595 |
->json_is({ expiration_date => '2022-01-01' }); |
| 1596 |
|
| 1597 |
is( $hold->discard_changes->expirationdate, '2022-01-01', 'expiration date changed correctly' ); |
| 1598 |
|
| 1599 |
$schema->storage->txn_rollback; |
| 1600 |
}; |