From 48984539c95d2e898bf3f3fc5cc733e6f8ee915f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 19 Aug 2020 12:17:32 +0100 Subject: [PATCH] Bug 19036: (follow-up) Improve test output 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. --- t/db_dependent/Koha/Account.t | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index 493e1ba639..9b37a08f8a 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -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; }; -- 2.20.1