|
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 2054-2056
subtest 'Bug 40866: API hold creation with override logs confirmations' => sub {
Link Here
|
| 2054 |
|
2055 |
|
| 2055 |
$schema->storage->txn_rollback; |
2056 |
$schema->storage->txn_rollback; |
| 2056 |
}; |
2057 |
}; |
|
|
2058 |
|
| 2059 |
subtest 'POST with debits embedding tests' => sub { |
| 2060 |
|
| 2061 |
plan tests => 4; |
| 2062 |
|
| 2063 |
$schema->storage->txn_begin; |
| 2064 |
|
| 2065 |
# Setup proper permissions and authentication |
| 2066 |
my $categorycode = $builder->build( { source => 'Category' } )->{categorycode}; |
| 2067 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
| 2068 |
my $password = 'thePassword123'; |
| 2069 |
|
| 2070 |
my $librarian = $builder->build_object( |
| 2071 |
{ |
| 2072 |
class => 'Koha::Patrons', |
| 2073 |
value => { |
| 2074 |
categorycode => $categorycode, |
| 2075 |
branchcode => $branchcode, |
| 2076 |
flags => 80, # borrowers (16) + reserveforothers (64) = 80 |
| 2077 |
} |
| 2078 |
} |
| 2079 |
); |
| 2080 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 2081 |
my $userid = $librarian->userid; |
| 2082 |
|
| 2083 |
my $patron = $builder->build_object( |
| 2084 |
{ |
| 2085 |
class => 'Koha::Patrons', |
| 2086 |
value => { |
| 2087 |
categorycode => $categorycode, |
| 2088 |
branchcode => $branchcode, |
| 2089 |
} |
| 2090 |
} |
| 2091 |
); |
| 2092 |
my $biblio = $builder->build_sample_biblio(); |
| 2093 |
my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 2094 |
|
| 2095 |
# Set up system preference to charge fees for holds |
| 2096 |
t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_placed' ); |
| 2097 |
|
| 2098 |
# Create a circulation rule with hold fee |
| 2099 |
Koha::CirculationRules->set_rules( |
| 2100 |
{ |
| 2101 |
categorycode => $patron->categorycode, |
| 2102 |
branchcode => undef, |
| 2103 |
itemtype => undef, |
| 2104 |
rules => { |
| 2105 |
hold_fee => 2.50, |
| 2106 |
} |
| 2107 |
} |
| 2108 |
); |
| 2109 |
|
| 2110 |
# Make sure pickup location checks doesn't get in the middle |
| 2111 |
my $mock_biblio = Test::MockModule->new('Koha::Biblio'); |
| 2112 |
$mock_biblio->mock( 'pickup_locations', sub { return Koha::Libraries->search; } ); |
| 2113 |
my $mock_item = Test::MockModule->new('Koha::Item'); |
| 2114 |
$mock_item->mock( 'pickup_locations', sub { return Koha::Libraries->search } ); |
| 2115 |
|
| 2116 |
# Test POST with embedding (should include automatically charged debits in response) |
| 2117 |
$t->post_ok( |
| 2118 |
"//$userid:$password@/api/v1/holds" => { 'x-koha-embed' => 'debits' } => json => { |
| 2119 |
patron_id => $patron->borrowernumber, |
| 2120 |
biblio_id => $biblio->biblionumber, |
| 2121 |
item_id => $item->itemnumber, |
| 2122 |
pickup_library_id => $branchcode, |
| 2123 |
} |
| 2124 |
)->status_is(201)->json_has( '/debits', 'debits embedded in POST response' ) |
| 2125 |
->json_is( '/debits/0/amount', 2.50, 'Hold fee automatically charged and embedded' ); |
| 2126 |
|
| 2127 |
$schema->storage->txn_rollback; |
| 2128 |
}; |