From 331c80d7b0516eb03701ae92501e757120880f56 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 23 Oct 2019 14:16:20 +0100 Subject: [PATCH] Bug 23049: (QA follow-up) Fix for missing types in test inserts Signed-off-by: Marcel de Rooy Signed-off-by: Martin Renvoize --- t/db_dependent/Accounts.t | 124 +++++++++++++++++++++++++++++++----- t/db_dependent/Koha/Account.t | 115 +++++++++++++++++++++++++++++---- t/db_dependent/Koha/Account/Lines.t | 20 +++++- 3 files changed, 229 insertions(+), 30 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index a7311b5a81..0611f846e3 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -114,9 +114,11 @@ my $sth = $dbh->prepare( amountoutstanding, date, description, - interface + interface, + accounttype, + debit_type_code ) - VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ? )" + VALUES ( ?, ?, (select date_sub(CURRENT_DATE, INTERVAL ? DAY) ), ?, ?, ?, ? )" ); my $days = 5; @@ -138,7 +140,7 @@ my $categorycode = $builder->build({ source => 'Category' })->{categorycode}; my $borrower = Koha::Patron->new( { firstname => 'Test', surname => 'Patron', categorycode => $categorycode, branchcode => $branchcode } )->store(); for my $data ( @test_data ) { - $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}, 'commandline'); + $sth->execute($borrower->borrowernumber, $data->{amount}, $data->{days_ago}, $data->{description}, 'commandline', $data->{amount} > 0 ? 'W' : undef, $data->{amount} >= 0 ? undef : 'OVERDUE' ); } purge_zero_balance_fees( $days ); @@ -956,9 +958,32 @@ subtest "Koha::Account::non_issues_charges tests" => sub { } ); - my $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store(); - my $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => -5, interface => 'commandline' })->store(); - my $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store(); + my $debit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'LOST' + } + )->store(); + my $credit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => -5, + interface => 'commandline', + accounttype => 'Pay' + } + )->store(); + my $offset = Koha::Account::Offset->new( + { + credit_id => $credit->id, + debit_id => $debit->id, + type => 'Payment', + amount => 0 + } + )->store(); purge_zero_balance_fees( 1 ); my $debit_2 = Koha::Account::Lines->find( $debit->id ); my $credit_2 = Koha::Account::Lines->find( $credit->id ); @@ -966,9 +991,32 @@ subtest "Koha::Account::non_issues_charges tests" => sub { ok( $credit_2, 'Credit was correctly not deleted when credit has balance' ); is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2, "The 2 account lines still exists" ); - $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 5, interface => 'commanline' })->store(); - $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store(); - $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store(); + $debit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => 5, + interface => 'commanline', + debit_type_code => 'LOST' + } + )->store(); + $credit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => 0, + interface => 'commandline', + accounttype => 'Pay' + } + )->store(); + $offset = Koha::Account::Offset->new( + { + credit_id => $credit->id, + debit_id => $debit->id, + type => 'Payment', + amount => 0 + } + )->store(); purge_zero_balance_fees( 1 ); $debit_2 = $credit_2 = undef; $debit_2 = Koha::Account::Lines->find( $debit->id ); @@ -977,9 +1025,32 @@ subtest "Koha::Account::non_issues_charges tests" => sub { ok( $credit_2, 'Credit was correctly not deleted when debit has balance' ); is( Koha::Account::Lines->count({ borrowernumber => $patron->id }), 2 + 2, "The 2 + 2 account lines still exists" ); - $debit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store(); - $credit = Koha::Account::Line->new({ borrowernumber => $patron->id, date => '1900-01-01', amountoutstanding => 0, interface => 'commandline' })->store(); - $offset = Koha::Account::Offset->new({ credit_id => $credit->id, debit_id => $debit->id, type => 'Payment', amount => 0 })->store(); + $debit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'LOST' + } + )->store(); + $credit = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1900-01-01', + amountoutstanding => 0, + interface => 'commandline', + accounttype => 'Pay' + } + )->store(); + $offset = Koha::Account::Offset->new( + { + credit_id => $credit->id, + debit_id => $debit->id, + type => 'Payment', + amount => 0 + } + )->store(); purge_zero_balance_fees( 1 ); $debit_2 = Koha::Account::Lines->find( $debit->id ); $credit_2 = Koha::Account::Lines->find( $credit->id ); @@ -1008,8 +1079,24 @@ subtest "Koha::Account::Offset credit & debit tests" => sub { my $account = Koha::Account->new({ patron_id => $borrower->id }); - my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store(); - my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store(); + my $line1 = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amount => 10, + amountoutstanding => 10, + interface => 'commandline', + debit_type_code => 'LOST' + } + )->store(); + my $line2 = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amount => 20, + amountoutstanding => 20, + interface => 'commandline', + debit_type_code => 'LOST' + } + )->store(); my $id = $account->pay( { @@ -1068,7 +1155,14 @@ subtest "Payment notice tests" => sub { }); my $account = Koha::Account->new({ patron_id => $borrower->id }); - my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 27, interface => 'commandline' })->store(); + my $line = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amountoutstanding => 27, + interface => 'commandline', + debit_type_code => 'LOST' + } + )->store(); my $letter = Koha::Notice::Templates->find( { code => 'ACCOUNT_PAYMENT' } ); $letter->content('[%- USE Price -%]A payment of [% credit.amount * -1 | $Price %] has been applied to your account.'); diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 568cbf283e..9efc8de7b1 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -80,9 +80,32 @@ subtest 'outstanding_debits() tests' => sub { $i++; } my $patron_2 = $builder->build_object({ class => 'Koha::Patrons' }); - Koha::Account::Line->new({ borrowernumber => $patron_2->id, amountoutstanding => -2, interface => 'commandline' })->store; - my $just_one = Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 3, amountoutstanding => 3, interface => 'commandline' })->store; - Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => -6, amountoutstanding => -6, interface => 'commandline' })->store; + Koha::Account::Line->new( + { + borrowernumber => $patron_2->id, + amountoutstanding => -2, + interface => 'commandline', + accounttype => 'Pay' + } + )->store; + my $just_one = Koha::Account::Line->new( + { + borrowernumber => $patron_2->id, + amount => 3, + amountoutstanding => 3, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron_2->id, + amount => -6, + amountoutstanding => -6, + interface => 'commandline', + accounttype => 'Pay' + } + )->store; $lines = $patron_2->account->outstanding_debits(); is( $lines->total_outstanding, 3, "Total if some outstanding debits and some credits is only debits" ); is( $lines->count, 1, "With 1 outstanding debits, we get back a Lines object with 1 lines" ); @@ -105,7 +128,15 @@ subtest 'outstanding_debits() tests' => sub { is( $lines->count, 0, "With no outstanding debits, we get back a Lines object with 0 lines" ); # create a pathological credit with amountoutstanding > 0 (BZ 14591) - Koha::Account::Line->new({ borrowernumber => $patron_4->id, amount => -3, amountoutstanding => 3, interface => 'commandline' })->store(); + Koha::Account::Line->new( + { + borrowernumber => $patron_4->id, + amount => -3, + amountoutstanding => 3, + interface => 'commandline', + accounttype => 'Pay' + } + )->store(); $lines = $account_4->outstanding_debits(); is( $lines->count, 0, 'No credits are confused with debits because of the amountoutstanding value' ); @@ -149,7 +180,15 @@ subtest 'outstanding_credits() tests' => sub { is( $lines->count, 0, "With no outstanding credits, we get back a Lines object with 0 lines" ); # create a pathological debit with amountoutstanding < 0 (BZ 14591) - Koha::Account::Line->new({ borrowernumber => $patron_2->id, amount => 2, amountoutstanding => -3, interface => 'commandline' })->store(); + Koha::Account::Line->new( + { + borrowernumber => $patron_2->id, + amount => 2, + amountoutstanding => -3, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store(); $lines = $account->outstanding_credits(); is( $lines->count, 0, 'No debits are confused with credits because of the amountoutstanding value' ); @@ -447,8 +486,24 @@ subtest 'reconcile_balance' => sub { $account->add_debit({ amount => 4, interface => 'commandline', type => 'OVERDUE' }); # Paid Off - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; is( $account->balance(), -5, "Account balance is -5" ); is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); @@ -485,8 +540,24 @@ subtest 'reconcile_balance' => sub { $account->add_debit({ amount => 4, interface => 'commandline', type => 'OVERDUE' }); # Paid Off - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; is( $account->balance(), 0, "Account balance is 0" ); is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); @@ -524,8 +595,24 @@ subtest 'reconcile_balance' => sub { $account->add_debit({ amount => 5, interface => 'commandline', type => 'OVERDUE' }); # Paid Off - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; - Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0, interface => 'commandline' })->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->id, + amount => 1, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store; is( $account->balance(), 5, "Account balance is 5" ); is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' ); @@ -814,7 +901,8 @@ subtest 'Koha::Account::Line::apply() handles lost items' => sub { date => '1900-01-01', amount => "-0.500000", amountoutstanding => "-0.500000", - interface => 'commandline' + interface => 'commandline', + accounttype => 'Pay' } )->store(); my $debits = $account->outstanding_debits; @@ -832,7 +920,8 @@ subtest 'Koha::Account::Line::apply() handles lost items' => sub { date => '1900-01-01', amount => "-0.500000", amountoutstanding => "-0.500000", - interface => 'commandline' + interface => 'commandline', + accounttype => 'Pay' } )->store(); $debits = $account->outstanding_debits; diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index 31ff05fd5e..a480ac656f 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -539,8 +539,24 @@ subtest "void() tests" => sub { my $account = Koha::Account->new({ patron_id => $borrower->id }); - my $line1 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 10, amountoutstanding => 10, interface => 'commandline' })->store(); - my $line2 = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amount => 20, amountoutstanding => 20, interface => 'commandline' })->store(); + my $line1 = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amount => 10, + amountoutstanding => 10, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store(); + my $line2 = Koha::Account::Line->new( + { + borrowernumber => $borrower->borrowernumber, + amount => 20, + amountoutstanding => 20, + interface => 'commandline', + debit_type_code => 'OVERDUE' + } + )->store(); is( $account->balance(), 30, "Account balance is 30" ); is( $line1->amountoutstanding, 10, 'First fee has amount outstanding of 10' ); -- 2.11.4.GIT