From ac5d4bebbdd0c49eb8f11eee6b7c99db7dd2dae0 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 21 Nov 2019 06:34:11 -0500
Subject: [PATCH] Bug 24075: Unit tests

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
---
 t/db_dependent/Circulation.t | 45 +++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t
index aff4ee918e..2cf83118b6 100755
--- a/t/db_dependent/Circulation.t
+++ b/t/db_dependent/Circulation.t
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 45;
+use Test::More tests => 46;
 use Test::MockModule;
 
 use Data::Dumper;
@@ -3341,6 +3341,49 @@ subtest 'CanBookBeIssued & RentalFeesCheckoutConfirmation' => sub {
     $itemtype->rentalcharge_daily('0')->store;
 };
 
+subtest "Test Backdating of Returns" => sub {
+    plan tests => 2;
+
+    my $branch = $library2->{branchcode};
+    my $biblio = $builder->build_sample_biblio();
+    my $item = $builder->build_sample_item(
+        {
+            biblionumber     => $biblio->biblionumber,
+            library          => $branch,
+            itype            => $itemtype,
+        }
+    );
+
+    my %a_borrower_data = (
+        firstname =>  'Kyle',
+        surname => 'Hall',
+        categorycode => $patron_category->{categorycode},
+        branchcode => $branch,
+    );
+    my $borrowernumber = Koha::Patron->new(\%a_borrower_data)->store->borrowernumber;
+    my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed;
+
+    my $due_date = dt_from_string;
+    my $issue = AddIssue( $borrower, $item->barcode, $due_date );
+    UpdateFine(
+        {
+            issue_id          => $issue->id(),
+            itemnumber        => $item->itemnumber,
+            borrowernumber    => $borrowernumber,
+            amount            => .25,
+            amountoutstanding => .25,
+            type              => q{}
+        }
+    );
+
+
+    my ( undef, $message ) = AddReturn( $item->barcode, $branch, undef, $due_date );
+
+    my $accountline = Koha::Account::Lines->find( { issue_id => $issue->id } );
+    is( $accountline->amountoutstanding, '0.000000', 'Fee amount outstanding was reduced to 0' );
+    is( $accountline->amount, '0.000000', 'Fee amount was reduced to 0' );
+};
+
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
 $cache->clear_from_cache('single_holidays');
-- 
2.24.0