Bug 20990: Unit tests for Koha::Account->outstanding_credits
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 25 Jun 2018 14:15:08 +0000 (11:15 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 13 Jul 2018 10:34:30 +0000 (10:34 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
t/db_dependent/Koha/Account.t

index e07afe4..55c1e66 100755 (executable)
@@ -19,7 +19,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 use Koha::Account;
 use Koha::Account::Lines;
@@ -83,6 +83,35 @@ subtest 'outstanding_debits() tests' => sub {
     $schema->storage->txn_rollback;
 };
 
+subtest 'outstanding_credits() tests' => sub {
+
+    plan tests => 5;
+
+    $schema->storage->txn_begin;
+
+    my $patron  = $builder->build_object({ class => 'Koha::Patrons' });
+    my $account = Koha::Account->new({ patron_id => $patron->id });
+
+    my @generated_lines;
+    push @generated_lines, $account->add_credit({ amount => 1 });
+    push @generated_lines, $account->add_credit({ amount => 2 });
+    push @generated_lines, $account->add_credit({ amount => 3 });
+    push @generated_lines, $account->add_credit({ amount => 4 });
+
+    my ( $total, $lines ) = $account->outstanding_credits();
+
+    is( $total, -10, 'Outstandig debits total is correctly calculated' );
+
+    my $i = 0;
+    foreach my $line ( @{ $lines->as_list } ) {
+        my $fetched_line = Koha::Account::Lines->find( $generated_lines[$i]->id );
+        is_deeply( $line->unblessed, $fetched_line->unblessed, "Fetched line matches the generated one ($i)" );
+        $i++;
+    }
+
+    $schema->storage->txn_rollback;
+};
+
 subtest 'add_credit() tests' => sub {
 
     plan tests => 15;