Bugzilla – Attachment 113084 Details for
Bug 23091
Add options to charge new or restore forgiven overdues when a lost item is returned
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23091: Add tests for _RestoreOverdueForLostAndFound
Bug-23091-Add-tests-for-RestoreOverdueForLostAndFo.patch (text/plain), 5.42 KB, created by
Martin Renvoize (ashimema)
on 2020-11-05 11:15:34 UTC
(
hide
)
Description:
Bug 23091: Add tests for _RestoreOverdueForLostAndFound
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-11-05 11:15:34 UTC
Size:
5.42 KB
patch
obsolete
>From fb3cdbd94c7e4ffde946af702bac04363196693a Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Mon, 13 Jul 2020 15:51:24 +0100 >Subject: [PATCH] Bug 23091: Add tests for _RestoreOverdueForLostAndFound > >This patch adds unit tests for the newly introduced >_RestoreOverdueForLostAndFound method in C4::Circulation. > >Test plan >1/ Read the new tests added to t/db_dependent/Circuation.t to ensure >they make sense >2/ Run the tests and verify they pass >3/ Signoff > >Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com> >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >--- > C4/Circulation.pm | 2 ++ > t/db_dependent/Circulation.t | 70 ++++++++++++++++++++++++++++++++++-- > 2 files changed, 70 insertions(+), 2 deletions(-) > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index b55f252a78..3d405402f3 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -1552,6 +1552,7 @@ sub AddIssue { > ); > > if ($lostreturn_policy) { >+ > if ( $lostreturn_policy eq 'charge' ) { > $actualissue //= Koha::Old::Checkouts->search( > { itemnumber => $item_unblessed->{itemnumber} }, >@@ -2107,6 +2108,7 @@ sub AddReturn { > ); > > if ($lostreturn_policy) { >+ > if ( $lostreturn_policy eq 'charge' ) { > $issue //= Koha::Old::Checkouts->search( > { itemnumber => $item->itemnumber }, >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index 9d12f60c49..35063635c8 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -22,6 +22,7 @@ use Test::More tests => 50; > use Test::Exception; > use Test::MockModule; > use Test::Deep qw( cmp_deeply ); >+use Test::Warn; > > use Data::Dumper; > use DateTime; >@@ -2447,7 +2448,7 @@ subtest 'AddReturn | is_overdue' => sub { > is( int($patron->account->balance()), 0, 'AddReturn: pass return_date => no overdue' ); > Koha::Account::Lines->search({ borrowernumber => $patron->borrowernumber })->delete; > >- subtest 'bug 22877' => sub { >+ subtest 'bug 22877 | Lost item return' => sub { > > plan tests => 3; > >@@ -2697,6 +2698,71 @@ subtest 'AddReturn | is_overdue' => sub { > }; > }; > >+subtest '_RestoreOverdueForLostAndFound' => sub { >+ >+ plan tests => 7; >+ >+ my $manager = $builder->build_object( { class => "Koha::Patrons" } ); >+ t::lib::Mocks::mock_userenv( >+ { patron => $manager, branchcode => $manager->branchcode } ); >+ >+ my $patron = $builder->build_object( { class => "Koha::Patrons" } ); >+ my $item = $builder->build_sample_item(); >+ >+ # No fine found >+ my $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); >+ is($result, 0, "0 returned when no overdue found"); >+ >+ # Fine not forgiven >+ my $account = $patron->account; >+ my $overdue = $account->add_debit( >+ { >+ amount => 30.00, >+ user_id => $manager->borrowernumber, >+ library_id => $library2->{branchcode}, >+ interface => 'test', >+ item_id => $item->itemnumber, >+ type => 'OVERDUE', >+ } >+ )->store(); >+ $overdue->status('LOST')->store(); >+ >+ $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); >+ is($result, 0, "0 returned when overdue found without forgival"); >+ $overdue->discard_changes; >+ is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); >+ >+ # Reset status >+ $overdue->status('LOST')->store(); >+ >+ # Fine forgiven >+ my $credit = $account->add_credit( >+ { >+ amount => 30.00, >+ user_id => $manager->borrowernumber, >+ library_id => $library2->{branchcode}, >+ interface => 'test', >+ type => 'FORGIVEN', >+ item_id => $item->itemnumber >+ } >+ ); >+ $credit->apply( { debits => [$overdue], offset_type => 'Forgiven' } ); >+ >+ $result = C4::Circulation::_RestoreOverdueForLostAndFound( $item->itemnumber); >+ >+ is( ref($result), 'Koha::Account::Line', 'Return a Koha::Account::Line object on sucess'); >+ $overdue->discard_changes; >+ is($overdue->status, 'RETURNED', 'Overdue status updated to RETURNED'); >+ is($overdue->amountoutstanding, $overdue->amount, 'Overdue outstanding restored'); >+ >+ # Missing parameters >+ warning_like { >+ C4::Circulation::_RestoreOverdueForLostAndFound( undef ) >+ } >+ qr/_RestoreOverdueForLostAndFound\(\) not supplied valid itemnumber/, >+ "parameter warning received for missing itemnumbernumber"; >+}; >+ > subtest '_FixOverduesOnReturn' => sub { > plan tests => 14; > >@@ -2755,7 +2821,7 @@ subtest '_FixOverduesOnReturn' => sub { > > is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' ); > isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )'); >- is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )'); >+ is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been set to returned ( status RETURNED )'); > is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" ); > is( $offset->amount + 0, -99, "Amount of offset is correct" ); > my $credit = $offset->credit; >-- >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 23091
:
96217
|
105529
|
105530
|
105531
|
105544
|
105545
|
105546
|
105547
|
105567
|
105649
|
106871
|
106872
|
106873
|
106874
|
106875
|
106876
|
106906
|
106907
|
106908
|
106909
|
106910
|
106911
|
106912
|
106961
|
107026
|
107027
|
107028
|
107029
|
107030
|
107031
|
107032
|
107033
|
107034
|
107100
|
107101
|
107102
|
107103
|
107104
|
107105
|
107106
|
107107
|
107108
|
107335
|
107336
|
107337
|
107338
|
107339
|
107340
|
107341
|
107342
|
107343
|
108718
|
108719
|
108720
|
108721
|
108722
|
108723
|
108724
|
109571
|
109572
|
109573
|
109574
|
109575
|
109576
|
109577
|
110660
|
110661
|
110662
|
110663
|
110664
|
110665
|
110666
|
110667
|
110720
|
110721
|
110722
|
110723
|
110724
|
110725
|
110726
|
110727
|
111501
|
111502
|
111503
|
111504
|
111505
|
111506
|
111507
|
111508
|
111935
|
111936
|
111965
|
111979
|
111980
|
111981
|
111982
|
111983
|
111984
|
111985
|
111986
|
111987
|
111988
|
111989
|
113081
|
113082
|
113083
| 113084 |
113085
|
113086
|
113087
|
113088
|
113089
|
113090
|
113091