|
Lines 336-347
subtest 'adjust() tests' => sub {
Link Here
|
| 336 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } |
336 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } |
| 337 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
337 |
qr/Update type not recognised/, 'Exception thrown for unrecognised type'; |
| 338 |
|
338 |
|
| 339 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_increment' } ) } |
339 |
throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) } |
| 340 |
qr/Update type not allowed on this accounttype/, |
340 |
qr/Update type not allowed on this accounttype/, |
| 341 |
'Exception thrown for type conflict'; |
341 |
'Exception thrown for type conflict'; |
| 342 |
|
342 |
|
| 343 |
# Increment an unpaid fine |
343 |
# Increment an unpaid fine |
| 344 |
$debit_2->adjust( { amount => 150, type => 'fine_increment' } )->discard_changes; |
344 |
$debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes; |
| 345 |
|
345 |
|
| 346 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
346 |
is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); |
| 347 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
347 |
is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); |
|
Lines 352-358
subtest 'adjust() tests' => sub {
Link Here
|
| 352 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
352 |
is( $offsets->count, 1, 'An offset is generated for the increment' ); |
| 353 |
my $THIS_offset = $offsets->next; |
353 |
my $THIS_offset = $offsets->next; |
| 354 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
354 |
is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); |
| 355 |
is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); |
355 |
is( $THIS_offset->type, 'fine_increment', 'Adjust type stored correctly' ); |
| 356 |
|
356 |
|
| 357 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
357 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); |
| 358 |
|
358 |
|
|
Lines 368-374
subtest 'adjust() tests' => sub {
Link Here
|
| 368 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
368 |
t::lib::Mocks::mock_preference( 'FinesLog', 1 ); |
| 369 |
|
369 |
|
| 370 |
# Increment the partially paid fine |
370 |
# Increment the partially paid fine |
| 371 |
$debit_2->adjust( { amount => 160, type => 'fine_increment' } )->discard_changes; |
371 |
$debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes; |
| 372 |
|
372 |
|
| 373 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
373 |
is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); |
| 374 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
374 |
is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); |
|
Lines 378-389
subtest 'adjust() tests' => sub {
Link Here
|
| 378 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
378 |
is( $offsets->count, 3, 'An offset is generated for the increment' ); |
| 379 |
$THIS_offset = $offsets->last; |
379 |
$THIS_offset = $offsets->last; |
| 380 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
380 |
is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); |
| 381 |
is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); |
381 |
is( $THIS_offset->type, 'fine_increment', 'Adjust type stored correctly' ); |
| 382 |
|
382 |
|
| 383 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
383 |
is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); |
| 384 |
|
384 |
|
| 385 |
# Decrement the partially paid fine, less than what was paid |
385 |
# Decrement the partially paid fine, less than what was paid |
| 386 |
$debit_2->adjust( { amount => 50, type => 'fine_increment' } )->discard_changes; |
386 |
$debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes; |
| 387 |
|
387 |
|
| 388 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
388 |
is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); |
| 389 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
389 |
is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); |
|
Lines 393-402
subtest 'adjust() tests' => sub {
Link Here
|
| 393 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
393 |
is( $offsets->count, 4, 'An offset is generated for the decrement' ); |
| 394 |
$THIS_offset = $offsets->last; |
394 |
$THIS_offset = $offsets->last; |
| 395 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
395 |
is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); |
| 396 |
is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); |
396 |
is( $THIS_offset->type, 'fine_decrement', 'Adjust type stored correctly' ); |
| 397 |
|
397 |
|
| 398 |
# Decrement the partially paid fine, more than what was paid |
398 |
# Decrement the partially paid fine, more than what was paid |
| 399 |
$debit_2->adjust( { amount => 30, type => 'fine_increment' } )->discard_changes; |
399 |
$debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes; |
| 400 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
400 |
is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); |
| 401 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
401 |
is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); |
| 402 |
is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' ); |
402 |
is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' ); |
|
Lines 405-411
subtest 'adjust() tests' => sub {
Link Here
|
| 405 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
405 |
is( $offsets->count, 5, 'An offset is generated for the decrement' ); |
| 406 |
$THIS_offset = $offsets->last; |
406 |
$THIS_offset = $offsets->last; |
| 407 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
407 |
is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); |
| 408 |
is( $THIS_offset->type, 'Fine Update', 'Adjust type stored correctly' ); |
408 |
is( $THIS_offset->type, 'fine_decrement', 'Adjust type stored correctly' ); |
| 409 |
|
409 |
|
| 410 |
my $overpayment_refund = $account->lines->last; |
410 |
my $overpayment_refund = $account->lines->last; |
| 411 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
411 |
is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); |
| 412 |
- |
|
|