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

(-)a/t/db_dependent/api/v1/holds.t (-1 / +73 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 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
};
(-)a/t/db_dependent/api/v1/patrons_holds.t (-2 / +74 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 188-190 subtest 'delete_public() tests' => sub { Link Here
188
189
189
    $schema->storage->txn_rollback;
190
    $schema->storage->txn_rollback;
190
};
191
};
191
- 
192
193
subtest 'debits embedding tests' => sub {
194
195
    plan tests => 8;
196
197
    $schema->storage->txn_begin;
198
199
    # Setup proper permissions and authentication
200
    my $categorycode = $builder->build( { source => 'Category' } )->{categorycode};
201
    my $branchcode   = $builder->build( { source => 'Branch' } )->{branchcode};
202
    my $password     = 'thePassword123';
203
204
    my $librarian = $builder->build_object(
205
        {
206
            class => 'Koha::Patrons',
207
            value => {
208
                categorycode => $categorycode,
209
                branchcode   => $branchcode,
210
                flags        => 80,              # borrowers (16) + reserveforothers (64) = 80
211
            }
212
        }
213
    );
214
    $librarian->set_password( { password => $password, skip_validation => 1 } );
215
    my $userid = $librarian->userid;
216
217
    my $patron = $builder->build_object(
218
        {
219
            class => 'Koha::Patrons',
220
            value => {
221
                categorycode => $categorycode,
222
                branchcode   => $branchcode,
223
            }
224
        }
225
    );
226
    my $biblio = $builder->build_sample_biblio();
227
228
    # Create a hold using the proper API method
229
    my $reserve_id = C4::Reserves::AddReserve(
230
        {
231
            branchcode     => $branchcode,
232
            borrowernumber => $patron->borrowernumber,
233
            biblionumber   => $biblio->biblionumber,
234
            priority       => 1,
235
        }
236
    );
237
238
    my $hold = Koha::Holds->find($reserve_id);
239
240
    # Create account lines and link them to the hold
241
    my $fee1 = $patron->account->add_debit(
242
        {
243
            amount      => 2.50,
244
            description => 'Hold placement fee',
245
            type        => 'RESERVE',
246
            interface   => 'intranet',
247
            hold_id     => $hold->id,
248
        }
249
    );
250
251
    # Test without embedding - should not include debits
252
    $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . "/holds" )->status_is(200)
253
        ->json_has('/0/hold_id')->json_hasnt( '/0/debits', 'No debits without embedding' );
254
255
    # Test with debits embedding - should include debits
256
    $t->get_ok(
257
        "//$userid:$password@/api/v1/patrons/" . $patron->id . "/holds",
258
        { 'x-koha-embed' => 'debits' }
259
    )->status_is(200)->json_has( '/0/debits', 'debits present when embedded' )
260
        ->json_is( '/0/debits/0/amount', 2.50, 'Account line amount correct' );
261
262
    $schema->storage->txn_rollback;
263
};

Return to bug 40817