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

(-)a/t/db_dependent/Koha/Account.t (-4 / +111 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 4;
22
use Test::More tests => 5;
23
use Test::Exception;
23
24
24
use Koha::Account;
25
use Koha::Account;
25
use Koha::Account::Lines;
26
use Koha::Account::Lines;
Lines 148-154 subtest 'add_credit() tests' => sub { Link Here
148
    is( $account->balance, -25, 'Patron has a balance of -25' );
149
    is( $account->balance, -25, 'Patron has a balance of -25' );
149
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
150
    is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' );
150
    is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' );
151
    is( $schema->resultset('Statistic')->count(), $statistics + 1, 'Action added to statistics' );
151
    is( $line_1->accounttype, $Koha::Account::account_type->{'payment'}, 'Account type is correctly set' );
152
    is( $line_1->accounttype, $Koha::Account::account_type_credit->{'payment'}, 'Account type is correctly set' );
152
153
153
    # Enable logs
154
    # Enable logs
154
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
155
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
Lines 167-173 subtest 'add_credit() tests' => sub { Link Here
167
    is( $account->balance, -62, 'Patron has a balance of -25' );
168
    is( $account->balance, -62, 'Patron has a balance of -25' );
168
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
169
    is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' );
169
    is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' );
170
    is( $schema->resultset('Statistic')->count(), $statistics + 2, 'Action added to statistics' );
170
    is( $line_2->accounttype, $Koha::Account::account_type->{'payment'} . $sip_code, 'Account type is correctly set' );
171
    is( $line_2->accounttype, $Koha::Account::account_type_credit->{'payment'} . $sip_code, 'Account type is correctly set' );
171
172
172
    # offsets have the credit_id set to accountlines_id, and debit_id is undef
173
    # offsets have the credit_id set to accountlines_id, and debit_id is undef
173
    my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next;
174
    my $offset_1 = Koha::Account::Offsets->search({ credit_id => $line_1->id })->next;
Lines 193-198 subtest 'add_credit() tests' => sub { Link Here
193
    $schema->storage->txn_rollback;
194
    $schema->storage->txn_rollback;
194
};
195
};
195
196
197
subtest 'add_debit() tests' => sub {
198
199
    plan tests => 13;
200
201
    $schema->storage->txn_begin;
202
203
    # delete logs and statistics
204
    my $action_logs = $schema->resultset('ActionLog')->search()->count;
205
    my $statistics  = $schema->resultset('Statistic')->search()->count;
206
207
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
208
    my $account =
209
      Koha::Account->new( { patron_id => $patron->borrowernumber } );
210
211
    is( $account->balance, 0, 'Patron has no balance' );
212
213
    throws_ok {
214
    $account->add_debit(
215
        {
216
            amount      => -5,
217
            description => 'amount validation failure',
218
            library_id  => $patron->branchcode,
219
            note        => 'this should fail anyway',
220
            type        => 'rent',
221
            user_id     => $patron->id        
222
        }
223
    ); } 'Koha::Exceptions::Account::AmountNotPositive', 'Expected validation exception thrown (amount)';
224
225
    throws_ok {
226
    $account->add_debit(
227
        {
228
            amount      => 5,
229
            description => 'type validation failure',
230
            library_id  => $patron->branchcode,
231
            note        => 'this should fail anyway',
232
            type        => 'failure',
233
            user_id     => $patron->id        
234
        }
235
    ); } 'Koha::Exceptions::Account::UnrecognisedType', 'Expected validation exception thrown (type)';
236
237
    # Disable logs
238
    t::lib::Mocks::mock_preference( 'FinesLog', 0 );
239
240
    my $line_1 = $account->add_debit(
241
        {
242
            amount      => 25,
243
            description => 'Rental charge of 25',
244
            library_id  => $patron->branchcode,
245
            note        => 'not really important',
246
            type        => 'rent',
247
            user_id     => $patron->id
248
        }
249
    );
250
251
    is( $account->balance, 25, 'Patron has a balance of 25' );
252
    is(
253
        $schema->resultset('ActionLog')->count(),
254
        $action_logs + 0,
255
        'No log was added'
256
    );
257
    is(
258
        $line_1->accounttype,
259
        $Koha::Account::account_type_debit->{'rent'},
260
        'Account type is correctly set'
261
    );
262
263
    # Enable logs
264
    t::lib::Mocks::mock_preference( 'FinesLog', 1 );
265
266
    my $sip_code = "1";
267
    my $line_2   = $account->add_debit(
268
        {
269
            amount      => 37,
270
            description => 'Rental charge of 37',
271
            library_id  => $patron->branchcode,
272
            note        => 'not really important',
273
            type        => 'rent',
274
            user_id     => $patron->id,
275
        }
276
    );
277
278
    is( $account->balance, 62, 'Patron has a balance of 62' );
279
    is(
280
        $schema->resultset('ActionLog')->count(),
281
        $action_logs + 1,
282
        'Log was added'
283
    );
284
    is(
285
        $line_2->accounttype,
286
        $Koha::Account::account_type_debit->{'rent'},
287
        'Account type is correctly set'
288
    );
289
290
    # offsets have the debit_id set to accountlines_id, and credit_id is undef
291
    my $offset_1 =
292
      Koha::Account::Offsets->search( { debit_id => $line_1->id } )->next;
293
    my $offset_2 =
294
      Koha::Account::Offsets->search( { debit_id => $line_2->id } )->next;
295
296
    is( $offset_1->debit_id,  $line_1->id, 'debit_id is set for debit 1' );
297
    is( $offset_1->credit_id, undef,       'credit_id is not set for debit 1' );
298
    is( $offset_2->debit_id,  $line_2->id, 'debit_id is set for debit 2' );
299
    is( $offset_2->credit_id, undef,       'credit_id is not set for debit 2' );
300
301
    $schema->storage->txn_rollback;
302
};
303
196
subtest 'lines() tests' => sub {
304
subtest 'lines() tests' => sub {
197
305
198
    plan tests => 1;
306
    plan tests => 1;
199
- 

Return to bug 21002