From 077f8375e1163201d73d4a8834d7816656c375f2 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 5 Jan 2018 17:46:51 -0300 Subject: [PATCH] Bug 12001: Add tests Yes, we need tests to make sure we understand what is going on in this subroutine. The different combination of HoldsInNoissuesCharge, RentalsInNoissuesCharge and ManInvInNoissuesCharge are tested here with the subroutine we are going to remove (GetMemberAccountBalance). In one of the next patches the new methods will be used to make sure we are not modifying the calculated values (except the formatting). Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Accounts.t | 173 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 171 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t index 51c094af05..2c276c82eb 100644 --- a/t/db_dependent/Accounts.t +++ b/t/db_dependent/Accounts.t @@ -18,17 +18,18 @@ use Modern::Perl; -use Test::More tests => 23; +use Test::More tests => 24; use Test::MockModule; use Test::Warn; use t::lib::TestBuilder; use t::lib::Mocks; +use C4::Members; use Koha::Account; use Koha::Account::Lines; -use Koha::Account::Line; use Koha::Account::Offsets; +use Koha::DateUtils qw( dt_from_string ); BEGIN { use_ok('C4::Accounts'); @@ -627,4 +628,172 @@ subtest "Koha::Account::chargelostitem tests" => sub { is( $procfee->amount, "2.040000", "Processing fee if processing fee"); }; +subtest "Koha::Account::non_issues_charges tests" => sub { + plan tests => 21; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my $today = dt_from_string; + my $res = 3; + my $rent = 5; + my $manual = 7; + Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + accountno => 1, + date => $today, + description => 'a Res fee', + accounttype => 'Res', + amountoutstanding => $res, + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + accountno => 2, + date => $today, + description => 'a Rental fee', + accounttype => 'Rent', + amountoutstanding => $rent, + } + )->store; + Koha::Account::Line->new( + { + borrowernumber => $patron->borrowernumber, + accountno => 3, + date => $today, + description => 'a Manual invoice fee', + accounttype => 'Copie', + amountoutstanding => $manual, + } + )->store; + Koha::AuthorisedValue->new( + { + category => 'MANUAL_INV', + authorised_value => 'Copie', + lib => 'Fee for copie', + } + )->store; + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); + my ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( $non_issues_charges, 0, + 'If 0|0|0 there should not have non issues charges' ); + is( $other_charges, 15, 'If 0|0|0 there should only have other charges' ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( $non_issues_charges, $manual, + 'If 0|0|1 Only Manual should be a non issue charge' ); + is( + $other_charges, + $res + $rent, + 'If 0|0|1 Res + Rent should be other charges' + ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( $non_issues_charges, $rent, + 'If 0|1|0 Only Rental should be a non issue charge' ); + is( + $other_charges, + $res + $manual, + 'If 0|1|0 Rent + Manual should be other charges' + ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( + $non_issues_charges, + $rent + $manual, + 'If 0|1|1 Rent + Manual should be non issues charges' + ); + is( $other_charges, $res, 'If 0|1|1 there should only have other charges' ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 0 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( $non_issues_charges, $res, + 'If 1|0|0 Only Res should be non issues charges' ); + is( + $other_charges, + $rent + $manual, + 'If 1|0|0 Rent + Manual should be other charges' + ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 0 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( + $non_issues_charges, + $res + $rent, + 'If 1|1|0 Res + Rent should be non issues charges' + ); + is( $other_charges, $manual, + 'If 1|1|0 Only Manual should be other charges' ); + + t::lib::Mocks::mock_preference( 'HoldsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'RentalsInNoissuesCharge', 1 ); + t::lib::Mocks::mock_preference( 'ManInvInNoissuesCharge', 1 ); + ( $total, $non_issues_charges, $other_charges ) = + C4::Members::GetMemberAccountBalance( $patron->borrowernumber ); + is( + $total, + $res + $rent + $manual, + 'Total charges should be Res + Rent + Manual' + ); + is( + $non_issues_charges, + $res + $rent + $manual, + 'If 1|1|1 Res + Rent + Manual should be non issues charges' + ); + is( $other_charges, 0, 'If 1|1|1 there should not have any other charges' ); +}; + 1; -- 2.14.1