Bugzilla – Attachment 118615 Details for
Bug 27995
Koha::Account::Line->apply should return the update Koha::Account::Line object
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27995: Unit tests
Bug-27995-Unit-tests.patch (text/plain), 4.79 KB, created by
Martin Renvoize (ashimema)
on 2021-03-22 15:59:54 UTC
(
hide
)
Description:
Bug 27995: Unit tests
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2021-03-22 15:59:54 UTC
Size:
4.79 KB
patch
obsolete
>From dc75140b28dd70307b195e8d603ad3fd47d3b2a4 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Fri, 19 Mar 2021 09:45:45 +0000 >Subject: [PATCH] Bug 27995: Unit tests > >This patch updates the unit tests for Koha::Account::Line->apply to >reflect the change we wish to make to the return value. > >Instead of returning the scalar amount of available credit left on the >credit line after calling apply, we want to return the full, updated, >Koha::Account::Line object including Koha::Object::Messages for the >result of renewals that may have taken place. >--- > t/db_dependent/Koha/Account/Line.t | 29 ++++++++++++++++------------- > 1 file changed, 16 insertions(+), 13 deletions(-) > >diff --git a/t/db_dependent/Koha/Account/Line.t b/t/db_dependent/Koha/Account/Line.t >index 3139b56601..0eaa469385 100755 >--- a/t/db_dependent/Koha/Account/Line.t >+++ b/t/db_dependent/Koha/Account/Line.t >@@ -175,7 +175,7 @@ subtest 'is_credit() and is_debit() tests' => sub { > > subtest 'apply() tests' => sub { > >- plan tests => 25; >+ plan tests => 29; > > $schema->storage->txn_begin; > >@@ -208,10 +208,9 @@ subtest 'apply() tests' => sub { > $debit_1->discard_changes; > > my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); >- my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); >- is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); >- $credit->discard_changes; >- is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); >+ $credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); >+ is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object'); >+ is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' ); > > # re-read debit info > $debit_1->discard_changes; >@@ -224,10 +223,8 @@ subtest 'apply() tests' => sub { > is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); > > $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); >- $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } ); >- is( $remaining_credit, 0, 'No remaining credit left' ); >- $credit->discard_changes; >- is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); >+ $credit = $credit->apply( { debits => [ $debits->as_list ] } ); >+ is( $credit->amountoutstanding * 1, 0, 'No remaining credit' ); > $debit_2->discard_changes; > is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' ); > >@@ -279,12 +276,12 @@ subtest 'apply() tests' => sub { > is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); > > $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); >- $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); >+ $credit_2 = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); > > is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); > is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); > is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); >- is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); >+ is( $credit_2->amountoutstanding * 1, 0, 'No remaining credit' ); > > my $library = $builder->build_object( { class => 'Koha::Libraries' } ); > my $biblio = $builder->build_sample_biblio(); >@@ -329,10 +326,16 @@ subtest 'apply() tests' => sub { > $module->mock('CanBookBeRenewed', sub { return 1; }); > my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); > my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; >- $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); >- >+ $credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); > is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); > >+ my @messages = @{$credit_renew->messages}; >+ is( $messages[0]->type, 'info', 'Info message added for renewal' ); >+ is( $messages[0]->message, 'renewal', 'Message is "renewal"' ); >+ is( $messages[0]->payload->{itemnumber}, $item->id, 'itemnumber found in payload' ); >+ is( $messages[0]->payload->{due_date}, 1, 'due_date key in payload' ); >+ is( $messages[0]->payload->{success}, 1, "'success' key in payload" ); >+ > $schema->storage->txn_rollback; > }; > >-- >2.20.1
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 27995
:
118511
|
118512
|
118615
|
118616
|
119182
|
119183
|
119203
|
119204
|
120010
|
120011
|
120078
|
120079
|
120080
|
120083
|
120085
|
120086
|
120087