View | Details | Raw Unified | Return to bug 40817
Collapse All | Expand All

(-)a/t/db_dependent/api/v1/holds.t (-1 / +75 lines)
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
};
(-)a/t/db_dependent/api/v1/patrons_holds.t (-2 / +78 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 3;
21
use Test::More tests => 4;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Mojo;
23
use Test::Mojo;
24
24
Lines 26-31 use t::lib::TestBuilder; Link Here
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
27
28
use Koha::Database;
28
use Koha::Database;
29
use C4::Reserves;
29
30
30
my $schema  = Koha::Database->new->schema;
31
my $schema  = Koha::Database->new->schema;
31
my $builder = t::lib::TestBuilder->new();
32
my $builder = t::lib::TestBuilder->new();
Lines 196-198 subtest 'delete_public() tests' => sub { Link Here
196
197
197
    $schema->storage->txn_rollback;
198
    $schema->storage->txn_rollback;
198
};
199
};
199
- 
200
201
subtest 'debits embedding tests' => sub {
202
203
    plan tests => 8;
204
205
    $schema->storage->txn_begin;
206
207
    # Setup proper permissions and authentication
208
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
209
    my $branchcode   = $builder->build( { source => 'Branch' } )->{branchcode};
210
    my $password     = 'thePassword123';
211
212
    my $librarian = $builder->build_object(
213
        {
214
            class => 'Koha::Patrons',
215
            value => {
216
                categorycode => $categorycode,
217
                branchcode   => $branchcode,
218
                flags        => 80,              # borrowers (16) + reserveforothers (64) = 80
219
            }
220
        }
221
    );
222
    $librarian->set_password( { password => $password, skip_validation => 1 } );
223
    my $userid = $librarian->userid;
224
225
    my $patron = $builder->build_object(
226
        {
227
            class => 'Koha::Patrons',
228
            value => {
229
                categorycode => $categorycode,
230
                branchcode   => $branchcode,
231
            }
232
        }
233
    );
234
    my $biblio = $builder->build_sample_biblio();
235
236
    # Create a hold using the proper API method
237
    my $reserve_id = C4::Reserves::AddReserve(
238
        {
239
            branchcode     => $branchcode,
240
            borrowernumber => $patron->borrowernumber,
241
            biblionumber   => $biblio->biblionumber,
242
            priority       => 1,
243
        }
244
    );
245
246
    my $hold = Koha::Holds->find($reserve_id);
247
248
    # Create account lines and link them to the hold
249
    my $fee1 = $patron->account->add_debit(
250
        {
251
            amount      => 2.50,
252
            description => 'Hold placement fee',
253
            type        => 'RESERVE',
254
            interface   => 'intranet',
255
            hold_id     => $hold->id,
256
        }
257
    );
258
259
    # Test without embedding - should not include debits
260
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . "/holds" )
261
        ->status_is(200)
262
        ->json_has('/0/hold_id')
263
        ->json_hasnt( '/0/debits', 'No debits without embedding' );
264
265
    # Test with debits embedding - should include debits
266
    $t->get_ok(
267
        "//$userid:$password@/api/v1/patrons/" . $patron->id . "/holds",
268
        { 'x-koha-embed' => 'debits' }
269
        )
270
        ->status_is(200)
271
        ->json_has( '/0/debits', 'debits present when embedded' )
272
        ->json_is( '/0/debits/0/amount', 2.50, 'Account line amount correct' );
273
274
    $schema->storage->txn_rollback;
275
};

Return to bug 40817