From 8cf4f78fa3f13ce4772200073ae6f3095219ed3d Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 15 Mar 2019 14:18:12 +0000 Subject: [PATCH] Bug 22511: Update tests Updated tests to check for 'status' change and fixed 'accounttype' and moved from t/db_dependent/Accounts.t to the more appropriate t/db_dependent/Koha/Account/Lines.t Signed-off-by: Martin Renvoize --- t/db_dependent/Accounts.t | 67 ---------------------------- t/db_dependent/Koha/Account/Lines.t | 68 +++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 67 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 8822ea8bec..635f61d576 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -957,73 +957,6 @@ subtest "Koha::Account::non_issues_charges tests" => sub { is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists, the last 2 have been deleted ok" ); }; -subtest "Koha::Account::Line::void tests" => sub { - - plan tests => 15; - - # Create a borrower - my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; - my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; - - my $borrower = Koha::Patron->new( { - cardnumber => 'dariahall', - surname => 'Hall', - firstname => 'Daria', - } ); - $borrower->categorycode( $categorycode ); - $borrower->branchcode( $branchcode ); - $borrower->store; - - my $account = Koha::Account->new({ patron_id => $borrower->id }); - - my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store(); - my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store(); - - is( $account->balance(), 30, "Account balance is 30" ); - is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' ); - is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' ); - - my $id = $account->pay( - { - lines => [$line1, $line2], - amount => 30, - } - ); - - my $account_payment = Koha::Account::Lines->find( $id ); - - is( $account->balance(), 0, "Account balance is 0" ); - - $line1->_result->discard_changes(); - $line2->_result->discard_changes(); - 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(); - - is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); - is( $account->balance(), 30, "Account balance is again 30" ); - - $account_payment->_result->discard_changes(); - $line1->_result->discard_changes(); - $line2->_result->discard_changes(); - - is( $account_payment->accounttype, 'VOID', 'Voided payment accounttype is VOID' ); - is( $account_payment->amount+0, 0, 'Voided payment amount is 0' ); - 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(); - $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' ) -}; - subtest "Koha::Account::Offset credit & debit tests" => sub { plan tests => 4; diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 1d9c8cfd6e..9c3345532a 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -479,4 +479,72 @@ subtest 'checkout() tests' => sub { $schema->storage->txn_rollback; }; +subtest "void() tests" => sub { + + plan tests => 15; + + # Create a borrower + my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; + my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; + + my $borrower = Koha::Patron->new( { + cardnumber => 'dariahall', + surname => 'Hall', + firstname => 'Daria', + } ); + $borrower->categorycode( $categorycode ); + $borrower->branchcode( $branchcode ); + $borrower->store; + + my $account = Koha::Account->new({ patron_id => $borrower->id }); + + my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10 })->store(); + my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20 })->store(); + + is( $account->balance(), 30, "Account balance is 30" ); + is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' ); + is( $line2->amountoutstanding, 20, 'Second fee has amount outstanding of 20' ); + + my $id = $account->pay( + { + lines => [$line1, $line2], + amount => 30, + } + ); + + my $account_payment = Koha::Account::Lines->find( $id ); + + is( $account->balance(), 0, "Account balance is 0" ); + + $line1->_result->discard_changes(); + $line2->_result->discard_changes(); + 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(); + + is( ref($ret), 'Koha::Account::Line', 'Void returns the account line' ); + is( $account->balance(), 30, "Account balance is again 30" ); + + $account_payment->_result->discard_changes(); + $line1->_result->discard_changes(); + $line2->_result->discard_changes(); + + is( $account_payment->accounttype, 'Pay', 'Voided payment accounttype is still Pay' ); + is( $account_payment->status, 'VOID', 'Voided payment status is VOID' ); + is( $account_payment->amount+0, 0, 'Voided payment amount is 0' ); + 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(); + $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' ) +}; + 1; -- 2.20.1