Bug 26704: Unit tests
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 29 Nov 2021 18:18:21 +0000 (15:18 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Tue, 15 Feb 2022 07:41:38 +0000 (21:41 -1000)
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
t/db_dependent/Koha/Item.t

index 0139cd4..ac47d8f 100755 (executable)
@@ -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;
+    };
+};