From 0167f4bbab37c2b662f4f39354f152ffec846d62 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 12 Sep 2019 15:16:04 -0300 Subject: [PATCH] Bug 6759: (QA follow-up) Unit tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Patron.t | 84 +++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Patron.t b/t/db_dependent/Koha/Patron.t index 76bbed8b84..eea40c382d 100644 --- a/t/db_dependent/Koha/Patron.t +++ b/t/db_dependent/Koha/Patron.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 1; +use Test::More tests => 2; use Test::Exception; use Koha::Database; @@ -72,3 +72,85 @@ subtest 'add_guarantor() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'add_enrolment_fee_if_needed() tests' => sub { + + plan tests => 2; + + subtest 'category has enrolment fee' => sub { + plan tests => 7; + + $schema->storage->txn_begin; + + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { + enrolmentfee => 20 + } + } + ); + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode + } + } + ); + + my $enrollment_fee = $patron->add_enrolment_fee_if_needed(); + is( $enrollment_fee * 1, 20, 'Enrolment fee amount is correct' ); + my $account = $patron->account; + is( $patron->account->balance * 1, 20, 'Patron charged the enrolment fee' ); + # second enrolment fee, new + $enrollment_fee = $patron->add_enrolment_fee_if_needed(0); + # third enrolment fee, renewal + $enrollment_fee = $patron->add_enrolment_fee_if_needed(1); + is( $patron->account->balance * 1, 60, 'Patron charged the enrolment fees' ); + + my @debits = $account->outstanding_debits; + is( scalar @debits, 3, '3 enrolment fees' ); + is( $debits[0]->accounttype, 'ACCOUNT', 'Account type set correctly' ); + is( $debits[1]->accounttype, 'ACCOUNT', 'Account type set correctly' ); + is( $debits[2]->accounttype, 'ACCOUNT_RENEW', 'Account type set correctly' ); + + $schema->storage->txn_rollback; + }; + + subtest 'no enrolment fee' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { + enrolmentfee => 0 + } + } + ); + + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode + } + } + ); + + my $enrollment_fee = $patron->add_enrolment_fee_if_needed(); + is( $enrollment_fee * 1, 0, 'No enrolment fee' ); + my $account = $patron->account; + is( $patron->account->balance, 0, 'Patron not charged anything' ); + + my @debits = $account->outstanding_debits; + is( scalar @debits, 0, 'no debits' ); + + $schema->storage->txn_rollback; + }; +}; -- 2.23.0