|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 18; |
20 |
use Test::More tests => 19; |
| 21 |
use Test::NoWarnings; |
21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
|
Lines 38-43
use Koha::Biblios;
Link Here
|
| 38 |
use Koha::Biblioitems; |
38 |
use Koha::Biblioitems; |
| 39 |
use Koha::Items; |
39 |
use Koha::Items; |
| 40 |
use Koha::CirculationRules; |
40 |
use Koha::CirculationRules; |
|
|
41 |
use Koha::Old::Holds; |
| 41 |
use Koha::Patron::Debarments qw(AddDebarment); |
42 |
use Koha::Patron::Debarments qw(AddDebarment); |
| 42 |
|
43 |
|
| 43 |
my $schema = Koha::Database->new->schema; |
44 |
my $schema = Koha::Database->new->schema; |
|
Lines 1834-1839
subtest 'delete() tests' => sub {
Link Here
|
| 1834 |
$schema->storage->txn_rollback; |
1835 |
$schema->storage->txn_rollback; |
| 1835 |
}; |
1836 |
}; |
| 1836 |
|
1837 |
|
|
|
1838 |
subtest 'delete_bulk) tests' => sub { |
| 1839 |
|
| 1840 |
plan tests => 12; |
| 1841 |
|
| 1842 |
$schema->storage->txn_begin; |
| 1843 |
|
| 1844 |
my $password = 'AbcdEFG123'; |
| 1845 |
my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); |
| 1846 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 1847 |
my $userid = $patron->userid; |
| 1848 |
|
| 1849 |
# Only have 'place_holds' subpermission |
| 1850 |
$builder->build( |
| 1851 |
{ |
| 1852 |
source => 'UserPermission', |
| 1853 |
value => { |
| 1854 |
borrowernumber => $patron->borrowernumber, |
| 1855 |
module_bit => 6, |
| 1856 |
code => 'place_holds', |
| 1857 |
}, |
| 1858 |
} |
| 1859 |
); |
| 1860 |
|
| 1861 |
# Disable logging |
| 1862 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
| 1863 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 1864 |
|
| 1865 |
my $biblio = $builder->build_sample_biblio; |
| 1866 |
my $item = $builder->build_sample_item( |
| 1867 |
{ |
| 1868 |
biblionumber => $biblio->biblionumber, |
| 1869 |
library => $patron->branchcode |
| 1870 |
} |
| 1871 |
); |
| 1872 |
|
| 1873 |
# Add a hold |
| 1874 |
my $hold = Koha::Holds->find( |
| 1875 |
AddReserve( |
| 1876 |
{ |
| 1877 |
branchcode => $patron->branchcode, |
| 1878 |
borrowernumber => $patron->borrowernumber, |
| 1879 |
biblionumber => $biblio->biblionumber, |
| 1880 |
priority => 1, |
| 1881 |
itemnumber => undef, |
| 1882 |
} |
| 1883 |
) |
| 1884 |
); |
| 1885 |
|
| 1886 |
$t->delete_ok( "//$userid:$password@/api/v1/holds/cancellation_bulk" => json => { hold_ids => [ $hold->id ] } ) |
| 1887 |
->status_is( 204, 'REST3.2.4' )->content_is( '', 'REST3.3.4' ); |
| 1888 |
|
| 1889 |
is( $hold->get_from_storage, undef, "Hold has been successfully deleted" ); |
| 1890 |
|
| 1891 |
my $hold_2 = Koha::Holds->find( |
| 1892 |
AddReserve( |
| 1893 |
{ |
| 1894 |
branchcode => $patron->branchcode, |
| 1895 |
borrowernumber => $patron->borrowernumber, |
| 1896 |
biblionumber => $biblio->biblionumber, |
| 1897 |
priority => 1, |
| 1898 |
itemnumber => undef, |
| 1899 |
} |
| 1900 |
) |
| 1901 |
); |
| 1902 |
|
| 1903 |
# Prevent warning 'No reserves HOLD_CANCELLATION letter transported by email' |
| 1904 |
my $mock_letters = Test::MockModule->new('C4::Letters'); |
| 1905 |
$mock_letters->mock( 'GetPreparedLetter', sub { return } ); |
| 1906 |
|
| 1907 |
$t->delete_ok( "//$userid:$password@/api/v1/holds/cancellation_bulk" => json => |
| 1908 |
{ hold_ids => [ $hold_2->id ], cancellation_reason => 'DAMAGED' } )->status_is( 204, 'REST3.2.4' ) |
| 1909 |
->content_is( '', 'REST3.3.4' ); |
| 1910 |
|
| 1911 |
my $old_hold_2 = Koha::Old::Holds->find( $hold_2->id ); |
| 1912 |
is( $old_hold_2->cancellation_reason, 'DAMAGED', "Hold successfully deleted with provided cancellation reason" ); |
| 1913 |
|
| 1914 |
my $hold_3 = Koha::Holds->find( |
| 1915 |
AddReserve( |
| 1916 |
{ |
| 1917 |
branchcode => $patron->branchcode, |
| 1918 |
borrowernumber => $patron->borrowernumber, |
| 1919 |
biblionumber => $biblio->biblionumber, |
| 1920 |
priority => 1, |
| 1921 |
itemnumber => undef, |
| 1922 |
} |
| 1923 |
) |
| 1924 |
); |
| 1925 |
|
| 1926 |
$t->delete_ok( "//$userid:$password@/api/v1/holds/cancellation_bulk" => json => |
| 1927 |
{ hold_ids => [ $hold_2->id, $hold_3->id ], cancellation_reason => 'DAMAGED' } ) |
| 1928 |
->status_is( 404, 'REST3.2.4' ) |
| 1929 |
->content_is( '{"error":"Hold not found","error_code":"not_found"}', 'REST3.3.4' ); |
| 1930 |
|
| 1931 |
isnt( $hold_3->get_from_storage, undef, "Hold 3 has not been deleted because cancellation_bulk failed." ); |
| 1932 |
|
| 1933 |
$schema->storage->txn_rollback; |
| 1934 |
}; |
| 1935 |
|
| 1837 |
subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { |
1936 |
subtest 'PUT /holds/{hold_id}/lowest_priority tests' => sub { |
| 1838 |
|
1937 |
|
| 1839 |
plan tests => 5; |
1938 |
plan tests => 5; |
| 1840 |
- |
|
|