|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 20; |
20 |
use Test::More tests => 21; |
| 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 42-47
use Koha::Items;
Link Here
|
| 42 |
use Koha::CirculationRules; |
42 |
use Koha::CirculationRules; |
| 43 |
use Koha::Old::Holds; |
43 |
use Koha::Old::Holds; |
| 44 |
use Koha::Patron::Debarments qw(AddDebarment); |
44 |
use Koha::Patron::Debarments qw(AddDebarment); |
|
|
45 |
use Koha::Holds; |
| 45 |
|
46 |
|
| 46 |
my $schema = Koha::Database->new->schema; |
47 |
my $schema = Koha::Database->new->schema; |
| 47 |
my $builder = t::lib::TestBuilder->new(); |
48 |
my $builder = t::lib::TestBuilder->new(); |
|
Lines 2109-2111
subtest 'Bug 40866: API hold creation with override logs confirmations' => sub {
Link Here
|
| 2109 |
|
2110 |
|
| 2110 |
$schema->storage->txn_rollback; |
2111 |
$schema->storage->txn_rollback; |
| 2111 |
}; |
2112 |
}; |
|
|
2113 |
|
| 2114 |
subtest 'POST with debits embedding tests' => sub { |
| 2115 |
|
| 2116 |
plan tests => 4; |
| 2117 |
|
| 2118 |
$schema->storage->txn_begin; |
| 2119 |
|
| 2120 |
# Setup proper permissions and authentication |
| 2121 |
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode}; |
| 2122 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 2123 |
my $password = 'thePassword123'; |
| 2124 |
|
| 2125 |
my $librarian = $builder->build_object( |
| 2126 |
{ |
| 2127 |
class => 'Koha::Patrons', |
| 2128 |
value => { |
| 2129 |
categorycode => $categorycode, |
| 2130 |
branchcode => $branchcode, |
| 2131 |
flags => 80, # borrowers (16) + reserveforothers (64) = 80 |
| 2132 |
} |
| 2133 |
} |
| 2134 |
); |
| 2135 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 2136 |
my $userid = $librarian->userid; |
| 2137 |
|
| 2138 |
my $patron = $builder->build_object( |
| 2139 |
{ |
| 2140 |
class => 'Koha::Patrons', |
| 2141 |
value => { |
| 2142 |
categorycode => $categorycode, |
| 2143 |
branchcode => $branchcode, |
| 2144 |
} |
| 2145 |
} |
| 2146 |
); |
| 2147 |
my $biblio = $builder->build_sample_biblio(); |
| 2148 |
my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 2149 |
|
| 2150 |
# Set up system preference to charge fees for holds |
| 2151 |
t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_placed' ); |
| 2152 |
|
| 2153 |
# Create a circulation rule with hold fee |
| 2154 |
Koha::CirculationRules->set_rules( |
| 2155 |
{ |
| 2156 |
categorycode => $patron->categorycode, |
| 2157 |
branchcode => undef, |
| 2158 |
itemtype => undef, |
| 2159 |
rules => { |
| 2160 |
hold_fee => 2.50, |
| 2161 |
} |
| 2162 |
} |
| 2163 |
); |
| 2164 |
|
| 2165 |
# Make sure pickup location checks doesn't get in the middle |
| 2166 |
my $mock_biblio = Test::MockModule->new('Koha::Biblio'); |
| 2167 |
$mock_biblio->mock( 'pickup_locations', sub { return Koha::Libraries->search; } ); |
| 2168 |
my $mock_item = Test::MockModule->new('Koha::Item'); |
| 2169 |
$mock_item->mock( 'pickup_locations', sub { return Koha::Libraries->search } ); |
| 2170 |
|
| 2171 |
# Test POST with embedding (should include automatically charged debits in response) |
| 2172 |
$t->post_ok( |
| 2173 |
"//$userid:$password@/api/v1/holds" => { 'x-koha-embed' => 'debits' } => json => { |
| 2174 |
patron_id => $patron->borrowernumber, |
| 2175 |
biblio_id => $biblio->biblionumber, |
| 2176 |
item_id => $item->itemnumber, |
| 2177 |
pickup_library_id => $branchcode, |
| 2178 |
} |
| 2179 |
) |
| 2180 |
->status_is(201) |
| 2181 |
->json_has( '/debits', 'debits embedded in POST response' ) |
| 2182 |
->json_is( '/debits/0/amount', 2.50, 'Hold fee automatically charged and embedded' ); |
| 2183 |
|
| 2184 |
$schema->storage->txn_rollback; |
| 2185 |
}; |