From a00623c0d9c8b827aa731fa7bc4ec13966af0340 Mon Sep 17 00:00:00 2001 From: Martin Renvoize 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/Line.t | 38 +++++++++------ 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 489ae7de36..3d253e6f0f 100755 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -358,7 +358,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 }; @@ -392,11 +392,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, @@ -417,7 +430,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 }; @@ -452,11 +465,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 f999d27dae..dc21d3b63b 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -1371,7 +1371,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'); @@ -3383,7 +3383,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/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; }; -- 2.20.1