From 350b42b283189dd663bd7970f43573129a235c36 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 6 Apr 2021 11:19:04 +0100 Subject: [PATCH] Bug 27927: Add Unit Tests Add a unit test to check that 'FORGIVEN' credits do not prompt an auto-renewal with `RenewAccruingItemWhenPaid` enabled. Test plan 1/ Apply the test patch 2/ Run t/db_dependent/Koha/Account/Line.t and confirm it fails 3/ Apply subsequent patch 4/ Re-run the test and confirm it passes Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Nick Clemens --- t/db_dependent/Koha/Account/Line.t | 40 ++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index d112b31906..da40474a9b 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -175,7 +175,7 @@ subtest 'is_credit() and is_debit() tests' => sub { subtest 'apply() tests' => sub { - plan tests => 25; + plan tests => 26; $schema->storage->txn_begin; @@ -327,10 +327,35 @@ subtest 'apply() tests' => sub { my $module = Test::MockModule->new('C4::Circulation'); $module->mock('AddRenewal', sub { $called = 1; }); $module->mock('CanBookBeRenewed', sub { return 1; }); - my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); + my $credit_forgive = $account->add_credit( + { + amount => 1, + user_id => $patron->id, + interface => 'cli', + type => 'FORGIVEN' + } + ); my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; - $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); + $credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } ); + is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' ); + $accountline = Koha::Account::Line->new( + { + issue_id => $checkout->id, + borrowernumber => $patron->id, + itemnumber => $item->id, + branchcode => $library->id, + date => \'NOW()', + debit_type_code => 'OVERDUE', + status => 'UNRETURNED', + interface => 'cli', + amount => '1', + amountoutstanding => '1', + } + )->store(); + my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); + $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; + $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); $schema->storage->txn_rollback; @@ -387,7 +412,7 @@ subtest 'Keep account info when related patron, staff, item or cash_register is subtest 'Renewal related tests' => sub { - plan tests => 7; + plan tests => 8; $schema->storage->txn_begin; @@ -428,10 +453,13 @@ subtest 'Renewal related tests' => sub { t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 ); - is ($line->renew_item, undef, 'Attempt to renew fails when syspref is not set'); + is ($line->renew_item({ interface => 'intranet' }), undef, 'Attempt to renew fails when syspref is not set'); t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); + t::lib::Mocks::mock_preference( 'RenewAccruingItemInOpac', 0 ); + is ($line->renew_item({ interface => 'opac' }), undef, 'Attempt to renew fails when syspref is not set - OPAC'); + t::lib::Mocks::mock_preference( 'RenewAccruingItemInOpac', 1 ); is_deeply( - $line->renew_item, + $line->renew_item({ interface => 'intranet' }), { itemnumber => $item->itemnumber, error => 'too_many', -- 2.11.0