From bc90450fcc3fed0bde56c805b3983f77678f42e3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 30 Sep 2021 10:01:19 -0300 Subject: [PATCH] Bug 29139: Add regression tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Koha/Account.t | 41 ++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Account.t b/t/db_dependent/Koha/Account.t index fa36c4b835..6cb55c29f3 100755 --- a/t/db_dependent/Koha/Account.t +++ b/t/db_dependent/Koha/Account.t @@ -684,7 +684,7 @@ subtest 'reconcile_balance' => sub { subtest 'pay() tests' => sub { - plan tests => 5; + plan tests => 6; $schema->storage->txn_begin; @@ -738,6 +738,45 @@ subtest 'pay() tests' => sub { my $payment = Koha::Account::Lines->find({accountlines_id => $result->{payment_id}}); is($payment->manager_id, undef, "manager_id left undefined when no userenv found"); + subtest 'UseEmailReceipts tests' => sub { + + plan tests => 5; + + t::lib::Mocks::mock_preference( 'UseEmailReceipts', 1 ); + + my %params; + + my $mocked_letters = Test::MockModule->new('C4::Letters'); + # we want to test the params + $mocked_letters->mock( 'GetPreparedLetter', sub { + %params = @_; + return 1; + }); + # we don't care about EnqueueLetter for now + $mocked_letters->mock( 'EnqueueLetter', sub { + return 1; + }); + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $account = $patron->account; + + my $debit_1 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } ); + my $debit_2 = $account->add_debit( { amount => 10, interface => 'commandline', type => 'OVERDUE' } ); + + $account->pay({ amount => 6, lines => [ $debit_1, $debit_2 ] }); + my @offsets = @{$params{substitute}{offsets}}; + + is( scalar @offsets, 2, 'Two offsets related to payment' ); + is( ref($offsets[0]), 'Koha::Account::Offset', 'Type is correct' ); + is( ref($offsets[1]), 'Koha::Account::Offset', 'Type is correct' ); + is( $offsets[0]->type, 'APPLY', 'Only APPLY offsets are passed to the notice' ); + is( $offsets[1]->type, 'APPLY', 'Only APPLY offsets are passed to the notice' ); + + $schema->storage->txn_rollback; + }; + $schema->storage->txn_rollback; }; -- 2.32.0