Bugzilla – Attachment 77194 Details for
Bug 20997
Add Koha::Account::Line::apply
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 20997: Add unit tests for Koha::Account::Line::apply
Bug-20997-Add-unit-tests-for-KohaAccountLineapply.patch (text/plain), 4.80 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-07-23 18:56:44 UTC
(
hide
)
Description:
Bug 20997: Add unit tests for Koha::Account::Line::apply
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-07-23 18:56:44 UTC
Size:
4.80 KB
patch
obsolete
>From b01a2c7ea3ab5fb3634e4da838c38b50368bc849 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 26 Jun 2018 11:51:41 -0300 >Subject: [PATCH] Bug 20997: Add unit tests for Koha::Account::Line::apply > >This patch adds unit tests for the mentioned method. > >To test: >- Apply this patch >- Run: > $ khell > k$ prove t/db_dependent/Koha/Account/Lines.t >=> FAIL: The method is not already implemented! > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > t/db_dependent/Koha/Account/Lines.t | 105 +++++++++++++++++++++++++++- > 1 file changed, 102 insertions(+), 3 deletions(-) > >diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t >index 11c8df121f..da09ef552c 100755 >--- a/t/db_dependent/Koha/Account/Lines.t >+++ b/t/db_dependent/Koha/Account/Lines.t >@@ -19,9 +19,12 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; >+use Test::Exception; > >+use Koha::Account; > use Koha::Account::Lines; >+use Koha::Account::Offsets; > use Koha::Items; > > use t::lib::TestBuilder; >@@ -29,7 +32,7 @@ use t::lib::TestBuilder; > my $schema = Koha::Database->new->schema; > my $builder = t::lib::TestBuilder->new; > >-subtest 'item' => sub { >+subtest 'item() tests' => sub { > > plan tests => 2; > >@@ -63,7 +66,7 @@ subtest 'item' => sub { > $schema->storage->txn_rollback; > }; > >-subtest 'total_outstanding' => sub { >+subtest 'total_outstanding() tests' => sub { > > plan tests => 5; > >@@ -128,3 +131,99 @@ subtest 'total_outstanding' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'is_credit() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+ my $account = $patron->account; >+ >+ my $credit = $account->add_credit({ amount => 100, user_id => $patron->id }); >+ >+ ok( $credit->is_credit, 'is_credit detects credits' ); >+ >+ my $debit = Koha::Account::Line->new( >+ { >+ borrowernumber => $patron->id, >+ accounttype => "F", >+ amount => 10, >+ })->store; >+ >+ ok( !$debit->is_credit, 'is_credit() detects debits' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'apply() tests' => sub { >+ >+ plan tests => 12; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $account = $patron->account; >+ >+ my $credit = $account->add_credit( { amount => 100, user_id => $patron->id } ); >+ >+ my $debit_1 = Koha::Account::Line->new( >+ { borrowernumber => $patron->id, >+ accounttype => "F", >+ amount => 10, >+ amountoutstanding => 10 >+ } >+ )->store; >+ >+ my $debit_2 = Koha::Account::Line->new( >+ { borrowernumber => $patron->id, >+ accounttype => "F", >+ amount => 100, >+ amountoutstanding => 100 >+ } >+ )->store; >+ >+ $credit->discard_changes; >+ $debit_1->discard_changes; >+ >+ my $remaining_credit = $credit->apply( { debit => $debit_1, offset_type => 'Manual Credit' } ); >+ is( $remaining_credit, 90, 'Remaining credit is correctly calculated' ); >+ $credit->discard_changes; >+ is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); >+ >+ # re-read debit info >+ $debit_1->discard_changes; >+ is( $debit_1->amountoutstanding * 1, 0, 'Debit has been cancelled' ); >+ >+ my $offsets = Koha::Account::Offsets->search( { credit_id => $credit->id, debit_id => $debit_1->id } ); >+ is( $offsets->count, 1, 'Only one offset is generated' ); >+ my $THE_offest = $offsets->next; >+ is( $THE_offest->amount * 1, 10, 'Amount was calculated correctly (less than the available credit)' ); >+ is( $THE_offest->type, 'Manual Credit', 'Passed type stored correctly' ); >+ >+ $remaining_credit = $credit->apply( { debit => $debit_2, offset_type => 'Manual Credit' } ); >+ is( $remaining_credit, 0, 'No remaining credit left' ); >+ $credit->discard_changes; >+ is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); >+ $debit_2->discard_changes; >+ is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' ); >+ >+ throws_ok >+ { $debit_1->apply({ debit => $credit }); } >+ 'Koha::Exceptions::Account::IsNotCredit', >+ '->apply() can only be used with credits'; >+ >+ throws_ok >+ { $credit->apply({ debit => $credit }); } >+ 'Koha::Exceptions::Account::IsNotDebit', >+ '->apply() can only be applied to credits'; >+ >+ throws_ok >+ { $credit->apply({ debit => $debit_1 }); } >+ 'Koha::Exceptions::Account::NoAvailableCredit', >+ '->apply() can only be used with outstanding credits'; >+ >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.18.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 20997
:
76451
|
76452
|
76459
|
76460
|
76461
|
76462
|
76463
|
76464
|
76465
|
76549
|
76550
|
76551
|
76654
|
76655
|
77194
|
77195
|
77196
|
77197
|
77198
|
77199
|
77310
|
77349
|
77350
|
77351
|
77352
|
77353
|
77354
|
77355
|
77356