Bug 17894 - Add unit tests
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 12 Jan 2017 14:41:53 +0000 (14:41 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Thu, 19 Jan 2017 11:15:25 +0000 (11:15 +0000)
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
t/db_dependent/Accounts.t

index fe3100c..d1cc6db 100644 (file)
@@ -18,7 +18,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 21;
+use Test::More tests => 22;
 use Test::MockModule;
 use Test::Warn;
 
@@ -303,6 +303,48 @@ subtest "Koha::Account::pay particular line tests" => sub {
     is( $line4->amountoutstanding, "4.000000", "Line 4 was not paid" );
 };
 
+subtest "Koha::Account::pay writeoff tests" => sub {
+
+    plan tests => 5;
+
+    # Create a borrower
+    my $categorycode = $builder->build({ source => 'Category' })->{ categorycode };
+    my $branchcode   = $builder->build({ source => 'Branch' })->{ branchcode };
+
+    my $borrower = Koha::Patron->new( {
+        cardnumber => 'chelseahall',
+        surname => 'Hall',
+        firstname => 'Chelsea',
+    } );
+    $borrower->categorycode( $categorycode );
+    $borrower->branchcode( $branchcode );
+    $borrower->store;
+
+    my $account = Koha::Account->new({ patron_id => $borrower->id });
+
+    my $line = Koha::Account::Line->new({ borrowernumber => $borrower->borrowernumber, amountoutstanding => 42 })->store();
+
+    is( $account->balance(), "42.000000", "Account balance is 42" );
+
+    my $id = $account->pay(
+        {
+            lines  => [$line],
+            amount => 42,
+            type   => 'writeoff',
+        }
+    );
+
+    $line->_result->discard_changes();
+
+    is( $line->amountoutstanding, "0.000000", "Line was written off" );
+
+    my $writeoff = Koha::Account::Lines->find( $id );
+
+    is( $writeoff->accounttype, 'W', 'Type is correct' );
+    is( $writeoff->description, 'Writeoff', 'Description is correct' );
+    is( $writeoff->amount, '-42.000000', 'Amount is correct' );
+};
+
 subtest "More Koha::Account::pay tests" => sub {
 
     plan tests => 6;