Bugzilla – Attachment 82688 Details for
Bug 21896
Add Koha::Account::reconcile_balance
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED OFF]Bug 21896: Add unit tests for Koha::Account::normalize_balance
Bug-21896-Add-unit-tests-for-KohaAccountnormalizeb.patch (text/plain), 6.43 KB, created by
Christopher Brannon
on 2018-11-28 00:21:07 UTC
(
hide
)
Description:
[SIGNED OFF]Bug 21896: Add unit tests for Koha::Account::normalize_balance
Filename:
MIME Type:
Creator:
Christopher Brannon
Created:
2018-11-28 00:21:07 UTC
Size:
6.43 KB
patch
obsolete
>From 50ec14f6640f28ca978e43a13b0972defbbe1d1d Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 27 Nov 2018 17:06:20 -0300 >Subject: [PATCH] Bug 21896: Add unit tests for > Koha::Account::normalize_balance > >--- > t/db_dependent/Koha/Account.t | 123 +++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 122 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t >index ff400c7552..ad9da10f64 100755 >--- a/t/db_dependent/Koha/Account.t >+++ b/t/db_dependent/Koha/Account.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 4; >+use Test::More tests => 5; > > use Koha::Account; > use Koha::Account::Lines; >@@ -225,3 +225,124 @@ subtest 'lines() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'normalize_balance' => sub { >+ >+ plan tests => 3; >+ >+ subtest 'more credit than debit' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $account = $patron->account; >+ >+ # Add Credits >+ $account->add_credit({ amount => 1 }); >+ $account->add_credit({ amount => 2 }); >+ $account->add_credit({ amount => 3 }); >+ $account->add_credit({ amount => 4 }); >+ $account->add_credit({ amount => 5 }); >+ >+ # Add Debits TODO: replace for calls to add_debit when time comes >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; >+ >+ # Paid Off >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ >+ is( $account->balance(), -5, "Account balance is -5" ); >+ is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); >+ is( $account->outstanding_credits->total_outstanding, -15, 'Outstanding credits sum -15' ); >+ >+ $account->normalize_balance(); >+ >+ is( $account->balance(), -5, "Account balance is -5" ); >+ is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' ); >+ is( $account->outstanding_credits->total_outstanding, -5, 'Outstanding credits sum -5' ); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'same debit than credit' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $account = $patron->account; >+ >+ # Add Credits >+ $account->add_credit({ amount => 1 }); >+ $account->add_credit({ amount => 2 }); >+ $account->add_credit({ amount => 3 }); >+ $account->add_credit({ amount => 4 }); >+ >+ # Add Debits TODO: replace for calls to add_debit when time comes >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; >+ >+ # Paid Off >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ >+ is( $account->balance(), 0, "Account balance is 0" ); >+ is( $account->outstanding_debits->total_outstanding, 10, 'Outstanding debits sum 10' ); >+ is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' ); >+ >+ $account->normalize_balance(); >+ >+ is( $account->balance(), 0, "Account balance is 0" ); >+ is( $account->outstanding_debits->total_outstanding, 0, 'No outstanding debits' ); >+ is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); >+ >+ $schema->storage->txn_rollback; >+ }; >+ >+ subtest 'more debit than credit' => sub { >+ >+ plan tests => 6; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $account = $patron->account; >+ >+ # Add Credits >+ $account->add_credit({ amount => 1 }); >+ $account->add_credit({ amount => 2 }); >+ $account->add_credit({ amount => 3 }); >+ $account->add_credit({ amount => 4 }); >+ >+ # Add Debits TODO: replace for calls to add_debit when time comes >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 1 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 2, amountoutstanding => 2 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 3, amountoutstanding => 3 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 4, amountoutstanding => 4 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 5, amountoutstanding => 5 })->store; >+ >+ # Paid Off >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ Koha::Account::Line->new({ borrowernumber => $patron->id, amount => 1, amountoutstanding => 0 })->store; >+ >+ is( $account->balance(), 5, "Account balance is 5" ); >+ is( $account->outstanding_debits->total_outstanding, 15, 'Outstanding debits sum 15' ); >+ is( $account->outstanding_credits->total_outstanding, -10, 'Outstanding credits sum -10' ); >+ >+ $account->normalize_balance(); >+ >+ is( $account->balance(), 5, "Account balance is 5" ); >+ is( $account->outstanding_debits->total_outstanding, 5, 'Outstanding debits sum 5' ); >+ is( $account->outstanding_credits->total_outstanding, 0, 'Outstanding credits sum 0' ); >+ >+ $schema->storage->txn_rollback; >+ }; >+}; >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21896
:
82684
|
82685
|
82688
|
82689
|
82690
|
82691
|
82692
|
82701
|
82702
|
82703
|
82720
|
82721
|
82722
|
82735
|
82736
|
82737
|
82738
|
82739
|
82740
|
82742
|
82811
|
82812
|
82813
|
82814
|
82815
|
82820