Bug 22200: Add Tests for change
[koha-equinox.git] / t / db_dependent / Circulation.t
index fde631e..0c12efb 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 128;
+use Test::More tests => 130;
 use Test::MockModule;
 
 use Data::Dumper;
@@ -692,7 +692,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 );
             {
                 amount      => $fines_amount,
                 interface   => 'test',
-                type        => 'fine',
+                type        => 'overdue',
                 item_id     => $item_to_auto_renew->{itemnumber},
                 description => "Some fines"
             }
@@ -706,7 +706,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 );
             {
                 amount      => $fines_amount,
                 interface   => 'test',
-                type        => 'fine',
+                type        => 'overdue',
                 item_id     => $item_to_auto_renew->{itemnumber},
                 description => "Some fines"
             }
@@ -720,7 +720,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 );
             {
                 amount      => $fines_amount,
                 interface   => 'test',
-                type        => 'fine',
+                type        => 'overdue',
                 item_id     => $item_to_auto_renew->{itemnumber},
                 description => "Some fines"
             }
@@ -865,7 +865,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 );
     is( $line->issue_id, $issue->id, 'Account line issue id matches' );
 
     my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
-    is( $offset->type, 'Fine', 'Account offset type is Fine' );
+    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
     is( $offset->amount, '15.000000', 'Account offset amount is 15.00' );
 
     t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
@@ -1988,6 +1988,8 @@ subtest 'AddReturn | is_overdue' => sub {
 
     my $library = $builder->build( { source => 'Branch' } );
     my $patron  = $builder->build( { source => 'Borrower', value => { categorycode => $patron_category->{categorycode} } } );
+    my $manager = $builder->build_object({ class => "Koha::Patrons" });
+    t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode });
 
     my $biblioitem = $builder->build( { source => 'Biblioitem' } );
     my $item = $builder->build(
@@ -2421,7 +2423,7 @@ subtest '_FixAccountForLostAndReturned' => sub {
         );
 
         my $manual_debit_amount = 80;
-        $account->add_debit( { amount => $manual_debit_amount, type => 'fine', interface =>'test' } );
+        $account->add_debit( { amount => $manual_debit_amount, type => 'overdue', interface =>'test' } );
 
         is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
 
@@ -2438,7 +2440,10 @@ subtest '_FixAccountForLostAndReturned' => sub {
 };
 
 subtest '_FixOverduesOnReturn' => sub {
-    plan tests => 6;
+    plan tests => 9;
+
+    my $manager = $builder->build_object({ class => "Koha::Patrons" });
+    t::lib::Mocks::mock_userenv({ patron => $manager, branchcode => $manager->branchcode });
 
     my $biblio = $builder->build_sample_biblio({ author => 'Hall, Kylie' });
 
@@ -2475,7 +2480,6 @@ subtest '_FixOverduesOnReturn' => sub {
     is( $accountline->amountoutstanding, '99.000000', 'Fine has the same amount outstanding as previously' );
     is( $accountline->status, 'RETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status RETURNED )');
 
-
     ## Run again, with exemptfine enabled
     $accountline->set(
         {
@@ -2494,6 +2498,10 @@ subtest '_FixOverduesOnReturn' => sub {
     is( $accountline->status, 'FORGIVEN', 'Open fine ( account type OVERDUE ) has been set to fine forgiven ( status FORGIVEN )');
     is( ref $offset, "Koha::Account::Offset", "Found matching offset for fine reduction via forgiveness" );
     is( $offset->amount, '-99.000000', "Amount of offset is correct" );
+    my $credit = $offset->credit;
+    is( ref $credit, "Koha::Account::Line", "Found matching credit for fine forgiveness" );
+    is( $credit->amount, '-99.000000', "Credit amount is set correctly" );
+    is( $credit->amountoutstanding + 0, 0, "Credit amountoutstanding is correctly set to 0" );
 };
 
 subtest 'Set waiting flag' => sub {