From 2a7f75082de3fa5c1898bb1736c9f78c0e7c7ba3 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 9 Dec 2025 17:21:23 +0000 Subject: [PATCH] Bug 40445: (follow-up) Update unit tests for negative cashup amounts Updated tests to reflect that negative amounts are now valid: 1. start_cashup_parameter_validation - Changed expected amount test from >= 0 to != 0, since amounts can now be negative 2. add_cashup - Updated invalid_amount subtest: - Removed test expecting negative amounts to throw exception - Added test confirming negative amounts are now accepted - Verifies negative amount is stored correctly - Kept tests for zero, non-numeric, and empty amounts All other tests remain unchanged as they don't specifically test for positive-only validation. To test: prove t/db_dependent/Koha/Cash/Register.t --- t/db_dependent/Koha/Cash/Register.t | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t index 875a1bc9c8c..3aab7e5d3a4 100755 --- a/t/db_dependent/Koha/Cash/Register.t +++ b/t/db_dependent/Koha/Cash/Register.t @@ -1325,8 +1325,8 @@ subtest 'start_cashup_parameter_validation' => sub { my $final_action_count = $register5->_result->search_related('cash_register_actions')->count; is( $final_action_count, $initial_action_count + 1, 'CASHUP_START action created in database' ); - # Verify expected amount calculation - ok( $start->amount >= 0, 'Expected amount calculated correctly' ); + # Verify expected amount calculation (can be positive or negative, but not zero) + ok( $start->amount != 0, 'Expected amount calculated correctly' ); # Verify timestamp is set ok( defined $start->timestamp, 'Timestamp is set on CASHUP_START action' ); @@ -1388,12 +1388,13 @@ subtest 'add_cashup' => sub { 'Koha::Exceptions::Account::AmountNotPositive', 'Zero amount throws AmountNotPositive exception'; - # Negative amount - throws_ok { - $register3->add_cashup( { manager_id => $manager->id, amount => '-5.00' } ); + # Negative amount is now valid (for float deficits) + my $negative_cashup; + lives_ok { + $negative_cashup = $register3->add_cashup( { manager_id => $manager->id, amount => '-5.00' } ); } - 'Koha::Exceptions::Account::AmountNotPositive', - 'Negative amount throws AmountNotPositive exception'; + 'Negative amount is accepted for float deficit scenarios'; + is( $negative_cashup->amount + 0, -5, 'Negative amount stored correctly' ); # Non-numeric amount throws_ok { -- 2.52.0