From fc7c21c81dfd833c037f061792b7785d7184018d 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 Signed-off-by: Nick Clemens --- 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 0073876e517..0921dfb6448 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -6868,7 +6868,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 9fa642be693..e10d4f83f72 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -2260,7 +2260,7 @@ subtest 'store() tests' => sub { subtest '_set_found_trigger() tests' => sub { - plan tests => 9; + plan tests => 13; $schema->storage->txn_begin; @@ -2337,6 +2337,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.5