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