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 1575-1577
subtest 'delete() tests' => sub {
Link Here
|
1575 |
|
1575 |
|
1576 |
$schema->storage->txn_rollback; |
1576 |
$schema->storage->txn_rollback; |
1577 |
}; |
1577 |
}; |
1578 |
- |
1578 |
|
|
|
1579 |
subtest 'PUT /holds/{hold_id}/hold_date tests' => sub { |
1580 |
|
1581 |
plan tests => 10; |
1582 |
|
1583 |
$schema->storage->txn_begin; |
1584 |
|
1585 |
my $password = 'AbcdEFG123'; |
1586 |
|
1587 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1588 |
|
1589 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); |
1590 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
1591 |
my $userid = $patron->userid; |
1592 |
$builder->build( |
1593 |
{ |
1594 |
source => 'UserPermission', |
1595 |
value => { |
1596 |
borrowernumber => $patron->borrowernumber, |
1597 |
module_bit => 6, |
1598 |
code => 'place_holds', |
1599 |
}, |
1600 |
} |
1601 |
); |
1602 |
|
1603 |
# Disable logging |
1604 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
1605 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
1606 |
|
1607 |
my $biblio = $builder->build_sample_biblio; |
1608 |
|
1609 |
# biblio-level hold |
1610 |
my $hold = Koha::Holds->find( |
1611 |
AddReserve( |
1612 |
{ |
1613 |
branchcode => $library_1->branchcode, |
1614 |
borrowernumber => $patron->borrowernumber, |
1615 |
biblionumber => $biblio->biblionumber, |
1616 |
priority => 1, |
1617 |
itemnumber => undef, |
1618 |
} |
1619 |
) |
1620 |
); |
1621 |
|
1622 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 0 ); |
1623 |
|
1624 |
$t->put_ok( |
1625 |
"//$userid:$password@/api/v1/holds/" . $hold->id . "/hold_date" => json => { hold_date => '2022-01-01' } ) |
1626 |
->status_is(403)->json_is( { error => 'Update not allowed' } ); |
1627 |
|
1628 |
t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 1 ); |
1629 |
|
1630 |
# Attempt to use an invalid pickup locations ends in 400 |
1631 |
$t->put_ok( "//$userid:$password@/api/v1/holds/0" . "/hold_date" => json => { hold_date => '2022-01-01' } ) |
1632 |
->status_is(404)->json_is( { error => 'Hold not found' } ); |
1633 |
|
1634 |
$t->put_ok( |
1635 |
"//$userid:$password@/api/v1/holds/" . $hold->id . "/hold_date" => json => { hold_date => '2022-01-01' } ) |
1636 |
->status_is(200)->json_is( { hold_date => '2022-01-01' } ); |
1637 |
|
1638 |
is( $hold->discard_changes->reservedate, '2022-01-01', 'hold date changed correctly' ); |
1639 |
|
1640 |
$schema->storage->txn_rollback; |
1641 |
}; |
1642 |
|
1643 |
subtest 'PUT /holds/{hold_id}/expiration_date tests' => sub { |
1644 |
|
1645 |
plan tests => 7; |
1646 |
|
1647 |
$schema->storage->txn_begin; |
1648 |
|
1649 |
my $password = 'AbcdEFG123'; |
1650 |
|
1651 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries', value => { pickup_location => 1 } } ); |
1652 |
|
1653 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); |
1654 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
1655 |
my $userid = $patron->userid; |
1656 |
$builder->build( |
1657 |
{ |
1658 |
source => 'UserPermission', |
1659 |
value => { |
1660 |
borrowernumber => $patron->borrowernumber, |
1661 |
module_bit => 6, |
1662 |
code => 'place_holds', |
1663 |
}, |
1664 |
} |
1665 |
); |
1666 |
|
1667 |
# Disable logging |
1668 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
1669 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
1670 |
|
1671 |
my $biblio = $builder->build_sample_biblio; |
1672 |
|
1673 |
# biblio-level hold |
1674 |
my $hold = Koha::Holds->find( |
1675 |
AddReserve( |
1676 |
{ |
1677 |
branchcode => $library_1->branchcode, |
1678 |
borrowernumber => $patron->borrowernumber, |
1679 |
biblionumber => $biblio->biblionumber, |
1680 |
priority => 1, |
1681 |
itemnumber => undef, |
1682 |
} |
1683 |
) |
1684 |
); |
1685 |
|
1686 |
# Attempt to use an invalid pickup locations ends in 400 |
1687 |
$t->put_ok( |
1688 |
"//$userid:$password@/api/v1/holds/0" . "/expiration_date" => json => { expiration_date => '2022-01-01' } ) |
1689 |
->status_is(404)->json_is( { error => 'Hold not found' } ); |
1690 |
|
1691 |
$t->put_ok( "//$userid:$password@/api/v1/holds/" |
1692 |
. $hold->id |
1693 |
. "/expiration_date" => json => { expiration_date => '2022-01-01' } )->status_is(200) |
1694 |
->json_is( { expiration_date => '2022-01-01' } ); |
1695 |
|
1696 |
is( $hold->discard_changes->expirationdate, '2022-01-01', 'expiration date changed correctly' ); |
1697 |
|
1698 |
$schema->storage->txn_rollback; |
1699 |
}; |