From 9f11b86214771ff72c5952c5549d488a06f44fb9 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 12 May 2020 09:24:28 +0100 Subject: [PATCH] Bug 25417: (QA follow-up) Add integration test for AddReturn Signed-off-by: Martin Renvoize --- t/db_dependent/Circulation.t | 50 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index e765b77840..42b18d1d11 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -2337,7 +2337,7 @@ subtest 'CanBookBeIssued + AutoReturnCheckedOutItems' => sub { subtest 'AddReturn | is_overdue' => sub { - plan tests => 5; + plan tests => 6; t::lib::Mocks::mock_preference('MarkLostItemsAsReturned', 'batchmod|moredetail|cronjob|additem|pendingreserves|onpayment'); t::lib::Mocks::mock_preference('CalculateFinesOnReturn', 1); @@ -2432,7 +2432,49 @@ subtest 'AddReturn | is_overdue' => sub { AddReturn( $item->{barcode}, $library->{branchcode} ); is( int( $patron->account->balance() ), 17, "Should have a single 10 days overdue fine and lost charge" ); - } + + # Cleanup + Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; + }; + + subtest 'bug 25417 | backdated return + exemptfine' => sub { + + plan tests => 6; + + t::lib::Mocks::mock_preference('CalculateFinesOnBackdate', 1); + + my $issue = AddIssue( $patron->unblessed, $item->{barcode}, $one_day_ago ); # date due was 1d ago + + # Fake fines cronjob on this checkout + my ($fine) = + CalcFine( $item, $patron->categorycode, $library->{branchcode}, + $one_day_ago, $now ); + UpdateFine( + { + issue_id => $issue->issue_id, + itemnumber => $item->{itemnumber}, + borrowernumber => $patron->borrowernumber, + amount => $fine, + due => output_pref($one_day_ago) + } + ); + is( int( $patron->account->balance() ), + 1, "Overdue fine of 1 day overdue" ); + + # Backdated return (dropbox mode example - charge should exist but be zero) + AddReturn( $item->{barcode}, $library->{branchcode}, 1, $one_day_ago ); + is( int( $patron->account->balance() ), + 0, "Overdue fine should be annulled" ); + my $lines = Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber }); + is( $lines->count, 1, "Overdue fine accountlines still exists"); + my $line = $lines->next; + is($line->amount+0,0, "Overdue fine amount has been reduced to 0"); + is($line->amountoutstanding+0,0, "Overdue fine amount outstanding has been reduced to 0"); + is($line->status,'RETURNED', "Overdue fine was fixed"); + + # Cleanup + Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; + }; }; subtest '_FixAccountForLostAndFound' => sub { @@ -2891,8 +2933,8 @@ subtest '_FixOverduesOnReturn' => sub { is( ref $credit, "Koha::Account::Line", "Found matching credit for fine forgiveness" ); is( $credit->amount + 0, -99, "Credit amount is set correctly" ); is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" ); - - # Bug 25417 - Only forgive fines where there is an amount oustanding to forgive + + # Bug 25417 - Only forgive fines where there is an amount outstanding to forgive $accountline->set( { debit_type_code => 'OVERDUE', -- 2.20.1