From 8097d4e222d4d6f8986a7a1049be1a2fb58d8704 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 15 Oct 2020 14:05:45 +0100 Subject: [PATCH] Bug 26175: (QA follow-up) Add tests for previous cashups https://bugs.koha-community.org/show_bug.cgi?id=26172 --- t/db_dependent/Koha/Cash/Register/Action.t | 65 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Cash/Register/Action.t b/t/db_dependent/Koha/Cash/Register/Action.t index 9fc08e808e..0d9c70e76c 100755 --- a/t/db_dependent/Koha/Cash/Register/Action.t +++ b/t/db_dependent/Koha/Cash/Register/Action.t @@ -81,7 +81,7 @@ subtest 'register' => sub { }; subtest 'cashup_summary' => sub { - plan tests => 8; + plan tests => 14; $schema->storage->txn_begin; @@ -281,6 +281,69 @@ subtest 'cashup_summary' => sub { is_deeply( $summary->{outgoing}, $expected_outgoing, "outgoing arrayref is correct" ); + # Backdate cashup1 so we can add a new cashup to check 'previous' + $cashup1->timestamp(\'NOW() - INTERVAL 2 MINUTE')->store(); + $cashup1->discard_changes; + + # Transaction 4 + my $debt4 = $builder->build_object( + { + class => 'Koha::Account::Lines', + value => { + register_id => undef, + amount => '2.75', + amountoutstanding => '0.00', + credit_type_code => undef, + debit_type_code => 'OVERDUE', + date => \'NOW() - INTERVAL 1 MINUTE' + }, + } + ); + my $income3 = $builder->build_object( + { + class => 'Koha::Account::Lines', + value => { + register_id => $register->id, + amount => '-2.75', + amountoutstanding => '0.00', + credit_type_code => 'PAYMENT', + debit_type_code => undef, + date => \'NOW() - INTERVAL 1 MINUTE' + }, + } + ); + $builder->build_object( + { + class => 'Koha::Account::Offsets', + value => { + credit_id => $income3->accountlines_id, + debit_id => $debt4->accountlines_id, + amount => '2.75', + type => 'Payment' + }, + } + ); + + my $cashup2 = + $register->add_cashup( { manager_id => $manager->id, amount => '2.75' } ); + + $summary = $cashup2->cashup_summary; + + is( $summary->{from_date}, $cashup1->timestamp, + "from_date returns the timestamp of the previous cashup action" ); + is( $summary->{to_date}, $cashup2->timestamp, + "to_date equals cashup timestamp" ); + is( ref( $summary->{income_transactions} ), + 'Koha::Account::Lines', + "income_transactions contains Koha::Account::Lines" ); + is( $summary->{income_transactions}->count, + 1, "income_transactions contains 2 transactions" ); + is( ref( $summary->{outgoing_transactions} ), + 'Koha::Account::Lines', + "outgoing_transactions contains Koha::Account::Lines" ); + is( $summary->{outgoing_transactions}->count, + 0, "outgoing_transactions contains 1 transaction" ); + $schema->storage->txn_rollback; }; -- 2.20.1