From f3c4d1e29aa7a3226165042c588b6a6262803507 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 17 Mar 2021 16:23:56 +0000 Subject: [PATCH] Bug 27971: Enhance unit tests This patch adds some additional unit tests for extra functionality included with this patchset. Test plan 1/ t/db_dependent/Koha/Account/Line.t should pass Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Account/Line.t | 51 +++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t index dffa5ebfcc3..3139b566019 100755 --- a/t/db_dependent/Koha/Account/Line.t +++ b/t/db_dependent/Koha/Account/Line.t @@ -686,7 +686,7 @@ subtest 'credits() and debits() tests' => sub { subtest "void() tests" => sub { - plan tests => 16; + plan tests => 23; $schema->storage->txn_begin; @@ -744,9 +744,35 @@ subtest "void() tests" => sub { is( $line1->amountoutstanding+0, 0, 'First fee has amount outstanding of 0' ); is( $line2->amountoutstanding+0, 0, 'Second fee has amount outstanding of 0' ); - my $ret = $account_payment->void({ interface => 'test' }); + throws_ok { + $line1->void( { interface => 'test' } ); + } + 'Koha::Exceptions::Account::IsNotCredit', + '->void() can only be used with credits'; + + throws_ok { + $account_payment->void(); + } + 'Koha::Exceptions::MissingParameter', + "->void() requires the `interface` parameter is passed"; + + throws_ok { + $account_payment->void( { interface => 'intranet' } ); + } + 'Koha::Exceptions::MissingParameter', + "->void() requires the `staff_id` parameter is passed when `interface` equals 'intranet'"; + throws_ok { + $account_payment->void( { interface => 'intranet', staff_id => $borrower->borrowernumber } ); + } + 'Koha::Exceptions::MissingParameter', + "->void() requires the `branch` parameter is passed when `interface` equals 'intranet'"; + + my $void = $account_payment->void({ interface => 'test' }); - is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); + is( ref($void), 'Koha::Account::Line', 'Void returns the account line' ); + is( $void->debit_type_code, 'VOID', 'Void returns the VOID account line' ); + is( $void->manager_id, undef, 'Void proceeds without manager_id OK if interface is not "intranet"' ); + is( $void->branchcode, undef, 'Void proceeds without branchcode OK if interface is not "intranet"' ); is( $account->balance(), 30, "Account balance is again 30" ); $account_payment->_result->discard_changes(); @@ -755,19 +781,22 @@ subtest "void() tests" => sub { is( $account_payment->credit_type_code, 'PAYMENT', 'Voided payment credit_type_code is still PAYMENT' ); is( $account_payment->status, 'VOID', 'Voided payment status is VOID' ); - is( $account_payment->amount+0, -30, 'Voided payment amount is -30' ); + is( $account_payment->amount+0, -30, 'Voided payment amount is still -30' ); is( $account_payment->amountoutstanding+0, 0, 'Voided payment amount outstanding is 0' ); is( $line1->amountoutstanding+0, 10, 'First fee again has amount outstanding of 10' ); is( $line2->amountoutstanding+0, 20, 'Second fee again has amount outstanding of 20' ); - # Accountlines that are not credits should be un-voidable - my $line1_pre = $line1->unblessed(); - $ret = $line1->void({ interface => 'test' }); - $line1->_result->discard_changes(); - my $line1_post = $line1->unblessed(); - is( $ret, undef, 'Attempted void on non-credit returns undef' ); - is_deeply( $line1_pre, $line1_post, 'Non-credit account line cannot be voided' ); + my $credit2 = $account->add_credit( { interface => 'test', amount => 10 } ); + $void = $credit2->void( + { + interface => 'intranet', + staff_id => $borrower->borrowernumber, + branch => $branchcode + } + ); + is( $void->manager_id, $borrower->borrowernumber, "->void stores the manager_id when it's passed"); + is( $void->branchcode, $branchcode, "->void stores the branchcode when it's passed"); $schema->storage->txn_rollback; }; -- 2.31.0