From 7f0c6a5aead2a63d0cd839f0afcfd11800df3a78 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Fri, 6 Mar 2020 09:00:08 +0000 Subject: [PATCH] Bug 24815: Add additional tests Signed-off-by: David Nind --- t/db_dependent/Koha/Cash/Register.t | 58 +++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) diff --git a/t/db_dependent/Koha/Cash/Register.t b/t/db_dependent/Koha/Cash/Register.t index 787ad2ef59..68d0644197 100644 --- a/t/db_dependent/Koha/Cash/Register.t +++ b/t/db_dependent/Koha/Cash/Register.t @@ -55,12 +55,21 @@ subtest 'library' => sub { }; subtest 'accountlines' => sub { - plan tests => 3; + plan tests => 5; $schema->storage->txn_begin; my $register = $builder->build_object( { class => 'Koha::Cash::Registers' } ); + + my $accountlines = $register->accountlines; + is( ref($accountlines), 'Koha::Account::Lines', +'Koha::Cash::Register->accountlines should always return a Koha::Account::Lines set' + ); + is( $accountlines->count, 0, +'Koha::Cash::Register->accountlines should always return the correct number of accountlines' + ); + my $accountline1 = $builder->build_object( { class => 'Koha::Account::Lines', @@ -74,7 +83,7 @@ subtest 'accountlines' => sub { } ); - my $accountlines = $register->accountlines; + $accountlines = $register->accountlines; is( ref($accountlines), 'Koha::Account::Lines', 'Koha::Cash::Register->accountlines should return a set of Koha::Account::Lines' ); @@ -146,7 +155,7 @@ subtest 'branch_default' => sub { }; subtest 'cashup' => sub { - plan tests => 3; + plan tests => 4; $schema->storage->txn_begin; @@ -200,9 +209,48 @@ subtest 'cashup' => sub { is( $last_cashup, undef, 'undef is returned when no cashup exists' ); }; - subtest 'outstanding_accountlines' => sub { + subtest 'cashups' => sub { plan tests => 4; + my $cashups = $register->cashups; + is( ref($cashups), 'Koha::Cash::Register::Actions', +'Koha::Cash::Register->cashups should always return a Koha::Cash::Register::Actions set' + ); + is( $cashups->count, 0, +'Koha::Cash::Register->cashups should always return the correct number of cashups' + ); + + my $cashup3 = + $register->add_cashup( + { manager_id => $patron->id, amount => '6.00' } ); + + $cashups = $register->cashups; + is( ref($cashups), 'Koha::Cash::Register::Actions', +'Koha::Cash::Register->cashups should return a Koha::Cash::Register::Actions set' + ); + is( $cashups->count, 1, +'Koha::Cash::Register->cashups should return the correct number of cashups' + ); + + $cashup3->delete; + }; + + subtest 'outstanding_accountlines' => sub { + plan tests => 6; + + my $accountlines = $register->outstanding_accountlines; + is( ref($accountlines), 'Koha::Account::Lines', +'Koha::Cash::Register->outstanding_accountlines should always return a Koha::Account::Lines set' + ); + is( $accountlines->count, 0, +'Koha::Cash::Register->outstanding_accountlines should always return the correct number of accountlines' + ); + + # add_cashup should not happen simultaneously with any other action + # that results in an accountline attached to the same cash register. + # In testing, we need to sleep for a second after each action that + # adds to the database. (We cannot use Time::Fake as timestamps are + # being added at the DB level, not in perl. my $accountline1 = $builder->build_object( { class => 'Koha::Account::Lines', @@ -216,7 +264,7 @@ subtest 'cashup' => sub { } ); - my $accountlines = $register->outstanding_accountlines; + $accountlines = $register->outstanding_accountlines; is( $accountlines->count, 2, 'No cashup, all accountlines returned' ); my $cashup3 = -- 2.11.0