From 5d2f72da81ed432dbcd609e0086b4861e0934f45 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 29 Nov 2021 15:18:21 -0300 Subject: [PATCH] Bug 26704: Unit tests Signed-off-by: Tomas Cohen Arazi Signed-off-by: Katrin Fischer --- t/db_dependent/Koha/Item.t | 59 +++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t index 0139cd40af..ac47d8fd48 100755 --- a/t/db_dependent/Koha/Item.t +++ b/t/db_dependent/Koha/Item.t @@ -20,7 +20,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 13; +use Test::More tests => 14; use Test::Exception; use C4::Biblio qw( GetMarcSubfieldStructure ); @@ -1167,3 +1167,60 @@ subtest 'columns_to_str' => sub { $schema->storage->txn_rollback; }; + +subtest 'store() tests' => sub { + + plan tests => 1; + + subtest '_set_found_trigger() tests' => sub { + + plan tests => 6; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + my $item = $builder->build_sample_item({ itemlost => 1, itemlost_on => dt_from_string() }); + + # Add a lost item debit + my $debit = $patron->account->add_debit( + { + amount => 10, + type => 'LOST', + item_id => $item->id, + interface => 'intranet', + } + ); + + my $lostreturn_policy = 'charge'; + + my $mocked_circ_rules = Test::MockModule->new('Koha::CirculationRules'); + $mocked_circ_rules->mock( 'get_lostreturn_policy', sub { return $lostreturn_policy; } ); + + # simulate it was found + $item->set( { itemlost => 0 } )->store; + + my $messages = $item->messages; + + my $message_1 = $messages->[0]; + + is( $message_1->type, 'info', 'type is correct' ); + is( $message_1->message, 'lost_refunded', 'message is correct' ); + + # Find the refund credit + my $credit = $debit->credits->next; + + is_deeply( + $message_1->payload, + { credit_id => $credit->id }, + 'type is correct' + ); + + my $message_2 = $messages->[1]; + + is( $message_2->type, 'info', 'type is correct' ); + is( $message_2->message, 'lost_charge', 'message is correct' ); + is( $message_2->payload, undef, 'no payload' ); + + $schema->storage->txn_rollback; + }; +}; -- 2.30.2