From f9f25ceda8fd157b6f5228c3f94d83f12d8ec5c8 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Thu, 21 Jul 2016 18:32:05 +0000
Subject: [PATCH] Bug 14826 - Unit Tests

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
---
 t/db_dependent/Accounts.t                             | 13 +++++++++++--
 t/db_dependent/Circulation.t                          | 15 ++++++++++++++-
 t/db_dependent/Circulation/NoIssuesChargeGuarantees.t | 12 +++++++++++-
 3 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/t/db_dependent/Accounts.t b/t/db_dependent/Accounts.t
index fcc63d3..34e3d23 100644
--- a/t/db_dependent/Accounts.t
+++ b/t/db_dependent/Accounts.t
@@ -27,6 +27,7 @@ use t::lib::TestBuilder;
 use Koha::Account;
 use Koha::Account::Lines;
 use Koha::Account::Line;
+use Koha::Account::Offsets;
 
 BEGIN {
     use_ok('C4::Accounts');
@@ -346,7 +347,7 @@ subtest "Koha::Account::pay writeoff tests" => sub {
 
 subtest "More Koha::Account::pay tests" => sub {
 
-    plan tests => 6;
+    plan tests => 8;
 
     # Create a borrower
     my $category   = $builder->build({ source => 'Category' })->{ categorycode };
@@ -376,6 +377,10 @@ subtest "More Koha::Account::pay tests" => sub {
     # make the full payment
     $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
 
+    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
+    is( $offset->amount(), '-100.000000', 'Offset amount is -100.00' );
+    is( $offset->type(), 'Payment', 'Offset type is Payment' );
+
     my $stat = $schema->resultset('Statistic')->search({
         branch  => $branch,
         type    => 'payment'
@@ -395,7 +400,7 @@ subtest "More Koha::Account::pay tests" => sub {
 
 subtest "Even more Koha::Account::pay tests" => sub {
 
-    plan tests => 6;
+    plan tests => 8;
 
     # Create a borrower
     my $category   = $builder->build({ source => 'Category' })->{ categorycode };
@@ -426,6 +431,10 @@ subtest "Even more Koha::Account::pay tests" => sub {
     # make the full payment
     $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
 
+    my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
+    is( $offset->amount, '-60.000000', 'Offset amount is -60.00' );
+    is( $offset->type, 'Payment', 'Offset type is payment' );
+
     my $stat = $schema->resultset('Statistic')->search({
         branch  => $branch,
         type    => 'payment'
diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t
index 9319924..0f8fa0b 100755
--- a/t/db_dependent/Circulation.t
+++ b/t/db_dependent/Circulation.t
@@ -17,7 +17,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 96;
+use Test::More tests => 102;
 
 use DateTime;
 
@@ -37,6 +37,8 @@ use Koha::IssuingRules;
 use Koha::Checkouts;
 use Koha::Patrons;
 use Koha::Subscriptions;
+use Koha::Account::Lines;
+use Koha::Account::Offsets;
 
 my $schema = Koha::Database->schema;
 $schema->storage->txn_begin;
@@ -752,6 +754,17 @@ C4::Context->dbh->do("DELETE FROM accountlines");
         }
     );
 
+    my $line = Koha::Account::Lines->search({ borrowernumber => $renewing_borrower->{borrowernumber} })->next();
+    is( $line->accounttype, 'FU', 'Account line type is FU' );
+    is( $line->lastincrement, '15.000000', 'Account line last increment is 15.00' );
+    is( $line->amountoutstanding, '15.000000', 'Account line amount outstanding is 15.00' );
+    is( $line->amount, '15.000000', 'Account line amount is 15.00' );
+    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->amount, '15.000000', 'Account offset amount is 15.00' );
+
     LostItem( $itemnumber, 1 );
 
     my $item = Koha::Database->new()->schema()->resultset('Item')->find($itemnumber);
diff --git a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t
index dc2c880..20042b5 100644
--- a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t
+++ b/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t
@@ -17,13 +17,15 @@
 
 use Modern::Perl;
 
-use Test::More tests => 2;
+use Test::More tests => 6;
 
 use t::lib::TestBuilder;
 use t::lib::Mocks;
 
 use C4::Accounts qw( manualinvoice );
 use C4::Circulation qw( CanBookBeIssued );
+use Koha::Account::Lines;
+use Koha::Account::Offsets;
 
 my $schema = Koha::Database->new->schema;
 $schema->storage->txn_begin;
@@ -63,6 +65,14 @@ manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
 ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
 is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
 
+my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
+is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
+is( $accountline->accounttype, "L", "Account type is L" );
+
+my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
+is( $offset->type, 'Manual Debit', 'Got correct offset type' );
+is( $offset->amount, '10.000000', 'Got amount of $10.00' );
+
 $schema->storage->txn_rollback;
 
 1;
-- 
2.10.2