Bug 19036: (follow-up) Improve test output
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 19 Aug 2020 11:17:32 +0000 (12:17 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 20 Aug 2020 10:31:59 +0000 (12:31 +0200)
This patch adds proper detail to the test output for the newly
introduced AutoCreditNumber feature and fixes the final test by adding
the 'interface' and 'amount' parameters to the Koha::Account::Line being
created so that we reach the Exception we are trying to catch and don't
die early.

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

t/db_dependent/Koha/Account.t

index 493e1ba..9b37a08 100755 (executable)
@@ -1084,42 +1084,44 @@ subtest 'Koha::Account::pay() generates credit number (Koha::Account::Line->stor
     for my $i (1..11) {
         $accountlines_id = $account->pay({ amount => '1.00', library_id => $library->id })->{payment_id};
         $accountline = Koha::Account::Lines->find($accountlines_id);
-        is($accountline->credit_number, $i);
+        is($accountline->credit_number, $i, "Incremental format credit number added for payments: $i");
     }
     $accountlines_id = $account->pay({ type => 'WRITEOFF', amount => '1.00', library_id => $library->id })->{payment_id};
     $accountline = Koha::Account::Lines->find($accountlines_id);
-    is($accountline->credit_number, undef);
+    is($accountline->credit_number, undef, "Incremental credit number not added for writeoff");
 
     t::lib::Mocks::mock_preference('AutoCreditNumber', 'annual');
     for my $i (1..11) {
         $accountlines_id = $account->pay({ amount => '1.00', library_id => $library->id })->{payment_id};
         $accountline = Koha::Account::Lines->find($accountlines_id);
-        is($accountline->credit_number, sprintf('%s-%04d', $year, $i));
+        is($accountline->credit_number, sprintf('%s-%04d', $year, $i), "Annual format credit number added for payments: " . sprintf('%s-%04d', $year, $i));
     }
     $accountlines_id = $account->pay({ type => 'WRITEOFF', amount => '1.00', library_id => $library->id })->{payment_id};
     $accountline = Koha::Account::Lines->find($accountlines_id);
-    is($accountline->credit_number, undef);
+    is($accountline->credit_number, undef, "Annual format credit number not aded for writeoff");
 
     t::lib::Mocks::mock_preference('AutoCreditNumber', 'branchyyyymmincr');
     for my $i (1..11) {
         $accountlines_id = $account->pay({ amount => '1.00', library_id => $library->id })->{payment_id};
         $accountline = Koha::Account::Lines->find($accountlines_id);
-        is($accountline->credit_number, sprintf('%s%d%02d%04d', $library->id, $year, $month, $i));
+        is($accountline->credit_number, sprintf('%s%d%02d%04d', $library->id, $year, $month, $i), "branchyyyymmincr format credit number added for payment: " . sprintf('%s%d%02d%04d', $library->id, $year, $month, $i));
     }
     $accountlines_id = $account->pay({ type => 'WRITEOFF', amount => '1.00', library_id => $library->id })->{payment_id};
     $accountline = Koha::Account::Lines->find($accountlines_id);
-    is($accountline->credit_number, undef);
+    is($accountline->credit_number, undef, "branchyyyymmincr format credit number not added for writeoff");
 
     throws_ok {
         Koha::Account::Line->new(
             {
+                interface        => 'test',
+                amount           => -1,
                 credit_type_code => $credit_type->code,
                 credit_number    => 42
             }
         )->store;
     }
-    qr/AutoCreditNumber is enabled but credit_number is already defined!/,
-      'Croaked on bad call to store';
+    'Koha::Exceptions::Account',
+"Exception thrown when AutoCreditNumber is enabled but credit_number is already defined";
 
     $schema->storage->txn_rollback;
 };