From 951a7bd2b7eca8659f8f49666cac160d197ada68 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Wed, 26 Jun 2024 13:55:04 +0000 Subject: [PATCH] Bug 28575: (QA follow-up): Add further unit tests This patch adds further unit tests for the messaging in _set_found_trigger prove t/db_dependent/Koha/Item.t --- t/db_dependent/Circulation.t | 1 - t/db_dependent/Koha/Item.t | 52 +++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index d079324c9b..9aa310bc31 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -6812,7 +6812,6 @@ subtest 'NoRefundOnLostFinesPaidAge' => sub { date => '1970-01-01 14:00:01', amountoutstanding => 0, amount => -5, - interface => 'commandline', credit_type_code => 'PAYMENT' } diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 5df382edf5..628cb6dae2 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -1902,7 +1902,7 @@ subtest 'store() tests' => sub { subtest '_set_found_trigger() tests' => sub { - plan tests => 9; + plan tests => 13; $schema->storage->txn_begin; @@ -1979,6 +1979,56 @@ subtest 'store() tests' => sub { $messages = $item->object_messages; is( scalar @{$messages}, 0, 'This item has no history, no associated lost fines, presumed not lost by patron, no messages returned'); + # NoRefundOnLostFinesPaidAge + t::lib::Mocks::mock_preference( 'NoRefundOnLostFinesPaidAge', 10 ); + $mocked_circ_rules->mock( 'get_lostreturn_policy', sub { return { lostreturn => 'refund' }; } ); + + $item = $builder->build_sample_item( { itemlost => 1, itemlost_on => dt_from_string() } ); + my $fine = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1970-01-01 14:00:01', + amount => 5, + amountoutstanding => 0, + interface => 'commandline', + debit_type_code => 'LOST', + itemnumber => $item->itemnumber + } + )->store(); + my $payment = Koha::Account::Line->new( + { + borrowernumber => $patron->id, + date => '1970-01-01 14:00:01', + amountoutstanding => 0, + amount => -5, + interface => 'commandline', + credit_type_code => 'PAYMENT' + } + )->store(); + my $offset = Koha::Account::Offset->new( + { + credit_id => $payment->id, + debit_id => $fine->id, + type => 'APPLY', + amount => -5, + created_on => '1971-01-01 14:00:01' + } + )->store(); + + $item->set( { itemlost => 0 } )->store; + + $messages = $item->object_messages; + + is( + scalar @{$messages}, 1, + 'This item has one message assigned' + ); + + my $message = $messages->[0]; + is( $message->type, 'info', 'type is correct' ); + is( $message->message, 'payment_not_refunded', 'message is correct' ); + is( $message->payload, undef, 'no payload' ); + $schema->storage->txn_rollback; }; -- 2.39.3 (Apple Git-146)