Bugzilla – Attachment 120968 Details for
Bug 22435
Clarify account_offset types by converting them to clear codes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22435: Update unit tests
Bug-22435-Update-unit-tests.patch (text/plain), 18.77 KB, created by
Martin Renvoize (ashimema)
on 2021-05-14 13:30:23 UTC
(
hide
)
Description:
Bug 22435: Update unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-05-14 13:30:23 UTC
Size:
18.77 KB
patch
obsolete
>From b92cd210b513bb958214431c87104f9993bec2e9 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 17 Mar 2021 17:48:23 +0000 >Subject: [PATCH] Bug 22435: Update unit tests > >--- > t/db_dependent/Accounts.t | 46 +++++++++++++++---- > t/db_dependent/Circulation.t | 4 +- > .../Circulation/NoIssuesChargeGuarantees.t | 2 +- > t/db_dependent/Koha/Account.t | 24 +++++----- > t/db_dependent/Koha/Account/Line.t | 38 +++++++++------ > t/db_dependent/Koha/Items.t | 27 ++++------- > 6 files changed, 84 insertions(+), 57 deletions(-) > >diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t >index caa9268888..7f6f0f1c3b 100755 >--- a/t/db_dependent/Accounts.t >+++ b/t/db_dependent/Accounts.t >@@ -329,7 +329,7 @@ subtest "Koha::Account::pay writeoff tests" => sub { > > subtest "More Koha::Account::pay tests" => sub { > >- plan tests => 8; >+ plan tests => 12; > > # Create a borrower > my $category = $builder->build({ source => 'Category' })->{ categorycode }; >@@ -363,11 +363,24 @@ subtest "More Koha::Account::pay tests" => sub { > my $account = Koha::Account->new( { patron_id => $borrowernumber } ); > my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } ); > # make the full payment >- $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' }); >+ my $payment = $account->pay( >+ { >+ lines => [$line], >+ amount => $amount, >+ library_id => $branch, >+ note => 'A payment note' >+ } >+ ); > >- my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next(); >- is( $offset->amount+0, -100, 'Offset amount is -100.00' ); >- is( $offset->type(), 'Payment', 'Offset type is Payment' ); >+ my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} }); >+ is( $offsets->count, 2, 'Two offsets recorded'); >+ my $offset = $offsets->next; >+ is( $offset->type(), 'CREATE', 'First offset type is CREATE' ); >+ is( $offset->amount+0, -100, 'First offset amount is -100.00' ); >+ $offset = $offsets->next; >+ is( $offset->type(), 'APPLY', 'Second offset type is APPLY' ); >+ is( $offset->amount+0, -100, 'Second offset amount is -100.00' ); >+ is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline'); > > my $stat = $schema->resultset('Statistic')->search({ > branch => $branch, >@@ -388,7 +401,7 @@ subtest "More Koha::Account::pay tests" => sub { > > subtest "Even more Koha::Account::pay tests" => sub { > >- plan tests => 8; >+ plan tests => 12; > > # Create a borrower > my $category = $builder->build({ source => 'Category' })->{ categorycode }; >@@ -423,11 +436,24 @@ subtest "Even more Koha::Account::pay tests" => sub { > my $account = Koha::Account->new( { patron_id => $borrowernumber } ); > my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } ); > # make the full payment >- $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' }); >+ my $payment = $account->pay( >+ { >+ lines => [$line], >+ amount => $partialamount, >+ library_id => $branch, >+ note => 'A payment note' >+ } >+ ); > >- my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next(); >- is( $offset->amount+0, -60, 'Offset amount is -60.00' ); >- is( $offset->type, 'Payment', 'Offset type is payment' ); >+ my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} }); >+ is( $offsets->count, 2, 'Two offsets recorded'); >+ my $offset = $offsets->next; >+ is( $offset->type(), 'CREATE', 'First offset type is CREATE' ); >+ is( $offset->amount+0, -60, 'First offset amount is -60.00' ); >+ $offset = $offsets->next; >+ is( $offset->type(), 'APPLY', 'Second offset type is APPLY' ); >+ is( $offset->amount+0, -60, 'Second offset amount is -60.00' ); >+ is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline'); > > my $stat = $schema->resultset('Statistic')->search({ > branch => $branch, >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index fd55e5e5f3..ec0b4aa4f9 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -1374,7 +1374,7 @@ subtest "CanBookBeRenewed tests" => sub { > is( $line->issue_id, $issue->id, 'Account line issue id matches' ); > > my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next(); >- is( $offset->type, 'OVERDUE', 'Account offset type is Fine' ); >+ is( $offset->type, 'CREATE', 'Account offset type is CREATE' ); > is( $offset->amount+0, 15, 'Account offset amount is 15.00' ); > > t::lib::Mocks::mock_preference('WhenLostForgiveFine','0'); >@@ -3386,7 +3386,7 @@ subtest '_FixOverduesOnReturn' => sub { > C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' ); > > $accountline->_result()->discard_changes(); >- my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Forgiven' })->next(); >+ my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'APPLY' })->next(); > > is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); > isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); >diff --git a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t >index 4746cb8ae1..84ad699d89 100755 >--- a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t >+++ b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t >@@ -81,7 +81,7 @@ is( $accountline->amountoutstanding+0, 10, "Found 10.00 amount outstanding" ); > is( $accountline->debit_type_code, "LOST", "Debit type is LOST" ); > > my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next(); >-is( $offset->type, 'Lost Item', 'Got correct offset type' ); >+is( $offset->type, 'CREATE', 'Got CREATE offset type' ); > is( $offset->amount+0, 10, 'Got amount of $10.00' ); > > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index f8e32a97b5..a66af97723 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -1264,19 +1264,19 @@ subtest 'Koha::Account::payout_amount() tests' => sub { > my $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } ); > is( $offsets->count, 4, 'Four offsets generated' ); > my $offset = $offsets->next; >- is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' ); >+ is( $offset->type, 'CREATE', 'CREATE offset added for payout line' ); > is( $offset->amount * 1, 10, 'Correct offset amount recorded' ); > $offset = $offsets->next; > is( $offset->credit_id, $credit_1->id, "Offset added against credit_1"); >- is( $offset->type, 'PAYOUT', "PAYOUT used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -2, 'Correct amount offset against credit_1' ); > $offset = $offsets->next; > is( $offset->credit_id, $credit_2->id, "Offset added against credit_2"); >- is( $offset->type, 'PAYOUT', "PAYOUT used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -3, 'Correct amount offset against credit_2' ); > $offset = $offsets->next; > is( $offset->credit_id, $credit_3->id, "Offset added against credit_3"); >- is( $offset->type, 'PAYOUT', "PAYOUT used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -5, 'Correct amount offset against credit_3' ); > > my $credit_5 = $account->add_credit( { amount => 5, interface => 'commandline' } ); >@@ -1297,11 +1297,11 @@ subtest 'Koha::Account::payout_amount() tests' => sub { > $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } ); > is( $offsets->count, 2, 'Two offsets generated' ); > $offset = $offsets->next; >- is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' ); >+ is( $offset->type, 'CREATE', 'CREATE offset added for payout line' ); > is( $offset->amount * 1, 2.50, 'Correct offset amount recorded' ); > $offset = $offsets->next; > is( $offset->credit_id, $credit_5->id, "Offset added against credit_5"); >- is( $offset->type, 'PAYOUT', "PAYOUT used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -2.50, 'Correct amount offset against credit_5' ); > > $schema->storage->txn_rollback; >@@ -1391,19 +1391,19 @@ subtest 'Koha::Account::payin_amount() tests' => sub { > my $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } ); > is( $offsets->count, 4, 'Four offsets generated' ); > my $offset = $offsets->next; >- is( $offset->type, 'Payment', 'Payment offset added for payin line' ); >+ is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); > is( $offset->amount * 1, -10, 'Correct offset amount recorded' ); > $offset = $offsets->next; > is( $offset->debit_id, $debit_1->id, "Offset added against debit_1"); >- is( $offset->type, 'Payment', "Payment used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -2, 'Correct amount offset against debit_1' ); > $offset = $offsets->next; > is( $offset->debit_id, $debit_2->id, "Offset added against debit_2"); >- is( $offset->type, 'Payment', "Payment used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -3, 'Correct amount offset against debit_2' ); > $offset = $offsets->next; > is( $offset->debit_id, $debit_3->id, "Offset added against debit_3"); >- is( $offset->type, 'Payment', "Payment used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -5, 'Correct amount offset against debit_3' ); > > my $debit_5 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } ); >@@ -1424,11 +1424,11 @@ subtest 'Koha::Account::payin_amount() tests' => sub { > $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } ); > is( $offsets->count, 2, 'Two offsets generated' ); > $offset = $offsets->next; >- is( $offset->type, 'Payment', 'Payment offset added for payin line' ); >+ is( $offset->type, 'CREATE', 'CREATE offset added for payin line' ); > is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' ); > $offset = $offsets->next; > is( $offset->debit_id, $debit_5->id, "Offset added against debit_5"); >- is( $offset->type, 'Payment', "Payment used for offset_type" ); >+ is( $offset->type, 'APPLY', "APPLY used for offset_type" ); > is( $offset->amount * 1, -2.50, 'Correct amount offset against debit_5' ); > > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t >index f709c82924..5af94085e7 100755 >--- a/t/db_dependent/Koha/Account/Line.t >+++ b/t/db_dependent/Koha/Account/Line.t >@@ -232,7 +232,7 @@ subtest 'apply() tests' => sub { > is( $offsets->count, 1, 'Only one offset is generated' ); > $THE_offset = $offsets->next; > is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' ); >- is( $THE_offset->type, 'Credit Applied', 'Defaults to \'Credit Applied\' offset type' ); >+ is( $THE_offset->type, 'APPLY', 'Defaults to \'APPLY\' offset type' ); > > $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); > throws_ok >@@ -978,7 +978,7 @@ subtest "payout() tests" => sub { > > subtest "reduce() tests" => sub { > >- plan tests => 29; >+ plan tests => 34; > > $schema->storage->txn_begin; > >@@ -1101,12 +1101,16 @@ subtest "reduce() tests" => sub { > is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); > > my $offsets = Koha::Account::Offsets->search( >- { credit_id => $reduction->id, debit_id => $debit1->id } ); >- is( $offsets->count, 1, 'Only one offset is generated' ); >+ { credit_id => $reduction->id } ); >+ is( $offsets->count, 2, 'Two offsets generated' ); > my $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'CREATE', 'CREATE offset added for discount line'); > is( $THE_offset->amount * 1, >- -5, 'Correct amount was applied against debit' ); >- is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); >+ -5, 'Correct offset amount recorded'); >+ $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'APPLY', "APPLY offset added for 'DISCOUNT'" ); >+ is( $THE_offset->amount * 1, -5, 'Correct amount offset against debt'); >+ is( $THE_offset->debit_id, $debit1->accountlines_id, 'APPLY offset recorded the correct debit_id'); > > # Zero offset created when zero outstanding > # (Refund another 5 on paid debt of 20) >@@ -1121,12 +1125,16 @@ subtest "reduce() tests" => sub { > is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); > > $offsets = Koha::Account::Offsets->search( >- { credit_id => $reduction->id, debit_id => $debit1->id } ); >- is( $offsets->count, 1, 'Only one new offset is generated' ); >+ { credit_id => $reduction->id } ); >+ is( $offsets->count, 2, 'Two offsets generated' ); >+ $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'CREATE', 'CREATE offset added for refund line'); >+ is( $THE_offset->amount * 1, >+ -5, 'Correct offset amount recorded'); > $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'APPLY', "APPLY offset added for 'REFUND'" ); > is( $THE_offset->amount * 1, > 0, 'Zero offset created for already paid off debit' ); >- is( $THE_offset->type, 'REFUND', "Offset type set to 'REFUND'" ); > > # Compound reduction should not allow more than original amount > # (Reduction of 5 + 5 + 20 > 20) >@@ -1157,7 +1165,7 @@ subtest "reduce() tests" => sub { > }; > > subtest "cancel() tests" => sub { >- plan tests => 16; >+ plan tests => 18; > > $schema->storage->txn_begin; > >@@ -1243,13 +1251,15 @@ subtest "cancel() tests" => sub { > is( $account->balance() * 1, 15, "Account balance is 15" ); > > my $offsets = Koha::Account::Offsets->search( >- { credit_id => $cancellation->id, debit_id => $debit1->id } ); >- is( $offsets->count, 1, 'Only one offset is generated' ); >+ { credit_id => $cancellation->id } ); >+ is( $offsets->count, 2, 'Two offsets are generated' ); > my $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'CREATE', 'CREATE offset added for cancel line'); >+ is( $THE_offset->amount * 1, -10, 'Correct offset amount recorded' ); >+ $THE_offset = $offsets->next; >+ is( $THE_offset->type, 'APPLY', "APPLY offset added" ); > is( $THE_offset->amount * 1, > -10, 'Correct amount was applied against debit' ); >- is( $THE_offset->type, 'CANCELLATION', >- "Offset type set to 'CANCELLATION'" ); > > $schema->storage->txn_rollback; > }; >diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t >index 900004d912..b8767ad861 100755 >--- a/t/db_dependent/Koha/Items.t >+++ b/t/db_dependent/Koha/Items.t >@@ -347,8 +347,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $credit->apply( >- { debits => [ $debts->as_list ], offset_type => 'Writeoff' } ); >+ $credit->apply( { debits => [ $debts->as_list ] } ); > > # Simulate item marked as found > $item->itemlost(0)->store; >@@ -431,8 +430,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $credit->apply( >- { debits => [ $debts->as_list ], offset_type => 'Payment' } ); >+ $credit->apply( { debits => [ $debts->as_list ] } ); > > # Simulate item marked as found > $item->itemlost(0)->store; >@@ -630,8 +628,7 @@ subtest 'store' => sub { > } > ); > >- $payment->apply( >- { debits => [$lost_fee_line], offset_type => 'Payment' } ); >+ $payment->apply( { debits => [$lost_fee_line] } ); > > # Partially write off fee > my $write_off_amount = 25; >@@ -642,8 +639,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $write_off->apply( >- { debits => [$lost_fee_line], offset_type => 'Writeoff' } ); >+ $write_off->apply( { debits => [$lost_fee_line] } ); > > is( > $account->balance, >@@ -771,8 +767,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $payment->apply( >- { debits => [$lost_fee_line], offset_type => 'Payment' } ); >+ $payment->apply( { debits => [$lost_fee_line] } ); > > is( > $account->balance, >@@ -962,8 +957,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $credit->apply( >- { debits => [ $debts->as_list ], offset_type => 'Payment' } ); >+ $credit->apply( { debits => [ $debts->as_list ] } ); > > # Simulate item marked as found > $item->itemlost(0)->store; >@@ -1054,8 +1048,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $credit->apply( >- { debits => [ $debts->as_list ], offset_type => 'Payment' } ); >+ $credit->apply( { debits => [ $debts->as_list ] } ); > > # Fine not forgiven > my $overdue = $account->add_debit( >@@ -1165,8 +1158,7 @@ subtest 'store' => sub { > interface => 'test', > } > ); >- $credit->apply( >- { debits => [ $debts->as_list ], offset_type => 'Payment' } ); >+ $credit->apply( { debits => [ $debts->as_list ] } ); > > # Add overdue > my $overdue = $account->add_debit( >@@ -1196,8 +1188,7 @@ subtest 'store' => sub { > item_id => $item->itemnumber > } > ); >- $credit->apply( >- { debits => [$overdue], offset_type => 'Forgiven' } ); >+ $credit->apply( { debits => [$overdue] } ); > > # Simulate item marked as found > $item->itemlost(0)->store; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 22435
:
118340
|
118341
|
118541
|
118542
|
118543
|
118544
|
118545
|
118546
|
118547
|
120040
|
120041
|
120042
|
120043
|
120044
|
120045
|
120046
|
120963
|
120964
|
120965
|
120966
|
120967
|
120968
|
120969
|
120970
|
120979
|
120980
|
120981
|
120982
|
120983
|
120984
|
120985
|
120986
|
120987
|
120988
|
120989
|
120990
|
120991
|
121004
|
121005
|
121006
|
121007
|
121008
|
121009
|
121010
|
121011
|
121012
|
121013
|
121014
|
121015
|
121016
|
121028
|
121757
|
121758
|
121759
|
121760
|
121761
|
121762
|
121763
|
121764
|
121765
|
121766
|
121767
|
121768
|
121769
|
121960
|
121961
|
121962
|
121963
|
121964
|
121965
|
121966
|
121967
|
121968
|
121969
|
121970
|
121971
|
121972
|
122148
|
122149
|
122150
|
122151
|
122152
|
122153
|
122154
|
122155
|
122156
|
122157
|
122158
|
122159
|
122160
|
122161
|
122235
|
122236
|
122237
|
122238
|
122239
|
122240
|
122241
|
122242
|
122243
|
122244
|
122245
|
122246
|
122247
|
122248
|
122249
|
122250
|
122251
|
122252
|
122253
|
122256
|
122257
|
122258
|
122259
|
122260
|
122261
|
122262
|
122263
|
122264
|
122265
|
122266
|
122267
|
122268
|
122269
|
122270
|
122271
|
122272
|
122273
|
122274
|
122553
|
122554
|
122555
|
122556
|
122557
|
122558
|
122559
|
122560
|
122561
|
122562
|
122563
|
122564
|
122565
|
122566
|
122567
|
122568
|
122569
|
122570
|
122571
|
122586
|
122899
|
122900
|
122901
|
122902
|
122903
|
122904
|
122905
|
122906
|
122907
|
122908
|
122909
|
122910
|
122911
|
122912
|
122913
|
122914
|
122915
|
122916
|
122917
|
122918
|
122937
|
123423
|
123424
|
123425
|
123426
|
123427
|
123428
|
123429
|
123430
|
123431
|
123432
|
123433
|
123434
|
123435
|
123436
|
123437
|
123438
|
123439
|
123440
|
123441
|
123442
|
123443