From 9e449f323ffb9e26a6bd2284a02aec67ce9e3283 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 24 May 2021 10:57:24 +0100 Subject: [PATCH] Bug 28421: Unit Tests This patch adds test test cases for both a Voided Payment and Voided Writeoff. These cases need special handling in the refund process. Test plan 1/ Run t/db_dependent/Koha/Items.t 2/ Prior to this commit the test should pass 3/ After this commit the test should fail 4/ The subsequent commit should make the test pass again. --- t/db_dependent/Koha/Items.t | 66 ++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index 900004d912..633e1957b2 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -559,10 +559,12 @@ subtest 'store' => sub { }; subtest - 'Test with partial payement and write off, and remaining debt' => + 'Test with partial payment and write off, and remaining debt' => sub { - plan tests => 17; + plan tests => 19; + + t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 0 ); my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); my $item = $builder->build_sample_item( @@ -617,11 +619,11 @@ subtest 'store' => sub { is( $account->balance, $processfee_amount + $replacement_amount, - 'Balance is PROCESSING + L' + 'Balance is PROCESSING + LOST' ); - # Partially pay fee - my $payment_amount = 27; + # Partially pay fee (99 - 27 = 72) + my $payment_amount = 24; my $payment = $account->add_credit( { amount => $payment_amount, @@ -633,8 +635,8 @@ subtest 'store' => sub { $payment->apply( { debits => [$lost_fee_line], offset_type => 'Payment' } ); - # Partially write off fee - my $write_off_amount = 25; + # Partially write off fee (72 - 20 = 52) + my $write_off_amount = 20; my $write_off = $account->add_credit( { amount => $write_off_amount, @@ -642,21 +644,67 @@ subtest 'store' => sub { interface => 'test', } ); + $write_off->apply( { debits => [$lost_fee_line], offset_type => 'Writeoff' } ); + my $payment_amount_2 = 3; + my $payment_2 = $account->add_credit( + { + amount => $payment_amount_2, + type => 'PAYMENT', + interface => 'test', + } + ); + + $payment_2->apply( + { debits => [$lost_fee_line], offset_type => 'Payment' } ); + + # Partially write off fee (52 - 5 = 47) + my $write_off_amount_2 = 5; + my $write_off_2 = $account->add_credit( + { + amount => $write_off_amount_2, + type => 'WRITEOFF', + interface => 'test', + } + ); + + $write_off_2->apply( + { debits => [$lost_fee_line], offset_type => 'Writeoff' } ); + + is( + $account->balance, + $processfee_amount + + $replacement_amount - + $payment_amount - + $write_off_amount - + $payment_amount_2 - + $write_off_amount_2, + 'Balance is PROCESSING + LOST - PAYMENT 1 - WRITEOFF - PAYMENT 2 - WRITEOFF 2' + ); + + # VOID payment_2 and writeoff_2 + $payment_2->void({ interface => 'test' }); + $write_off_2->void({ interface => 'test' }); + is( $account->balance, $processfee_amount + $replacement_amount - $payment_amount - $write_off_amount, - 'Payment and write off applied' + 'Balance is PROCESSING + LOST - PAYMENT 1 - WRITEOFF (PAYMENT 2 and WRITEOFF 2 VOIDED)' ); # Store the amountoutstanding value $lost_fee_line->discard_changes; my $outstanding = $lost_fee_line->amountoutstanding; + is( + $outstanding + 0, + $replacement_amount - $payment_amount - $write_off_amount, + "Lost Fee Outstanding is LOST - PAYMENT 1 - WRITEOFF" + ); # Simulate item marked as found $item->itemlost(0)->store; @@ -689,7 +737,7 @@ subtest 'store' => sub { is( $credit_return->amount + 0, ( $payment_amount + $outstanding ) * -1, -'The account line of type LOST_FOUND has an amount equal to the payment + outstanding' +'The account line of type LOST_FOUND has an amount equal to the payment 1 + outstanding' ); is( $credit_return->amountoutstanding + 0, -- 2.20.1