From f5a7b06c58a7491f470fac6ff0c3a8f6ddf82a30 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 12 Jan 2017 14:41:53 +0000 Subject: [PATCH] Bug 17894 - Add unit tests Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- t/db_dependent/Accounts.t | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index fe3100c..d1cc6db 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -18,7 +18,7 @@ use Modern::Perl; -use Test::More tests => 21; +use Test::More tests => 22; use Test::MockModule; use Test::Warn; @@ -303,6 +303,48 @@ subtest "Koha::Account::pay particular line tests" => sub { is( $line4->amountoutstanding, "4.000000", "Line 4 was not paid" ); }; +subtest "Koha::Account::pay writeoff tests" => sub { + + plan tests => 5; + + # Create a borrower + my $categorycode = $builder->build({ source => 'Category' })->{ categorycode }; + my $branchcode = $builder->build({ source => 'Branch' })->{ branchcode }; + + my $borrower = Koha::Patron->new( { + cardnumber => 'chelseahall', + surname => 'Hall', + firstname => 'Chelsea', + } ); + $borrower->categorycode( $categorycode ); + $borrower->branchcode( $branchcode ); + $borrower->store; + + my $account = Koha::Account->new({ patron_id => $borrower->id }); + + my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42 })->store(); + + is( $account->balance(), "42.000000", "Account balance is 42" ); + + my $id = $account->pay( + { + lines => [$line], + amount => 42, + type => 'writeoff', + } + ); + + $line->_result->discard_changes(); + + is( $line->amountoutstanding, "0.000000", "Line was written off" ); + + my $writeoff = Koha::Account::Lines->find( $id ); + + is( $writeoff->accounttype, 'W', 'Type is correct' ); + is( $writeoff->description, 'Writeoff', 'Description is correct' ); + is( $writeoff->amount, '-42.000000', 'Amount is correct' ); +}; + subtest "More Koha::Account::pay tests" => sub { plan tests => 6; -- 2.9.3