Bug 29234: Unit test
authorNick Clemens <nick@bywatersolutions.com>
Mon, 27 Mar 2023 10:58:43 +0000 (10:58 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 31 Mar 2023 09:56:49 +0000 (11:56 +0200)
This patch adds a test that a pending stock rotation transfer is initiated on
checkin, as well as updating the defaults for creating transfer objects

To test:
prove -v t/db_dependent/Circulation.t

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/Circulation.t
t/lib/TestBuilder.pm

index ba4c34f..1bbefe7 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 65;
+use Test::More tests => 66;
 use Test::Exception;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
@@ -5818,6 +5818,31 @@ subtest 'Tests for BlockReturnOfWithdrawnItems' => sub {
         [ 0, { NotIssued => $item->barcode, withdrawn => 1 }, undef, {} ], "Item returned as withdrawn, no other messages");
 };
 
+subtest 'Tests for transfer not in transit' => sub {
+
+    plan tests => 2;
+
+
+    # These tests are to ensure a 'pending' transfer, generated by
+    # stock rotation, will be advanced when checked in
+
+    my $item = $builder->build_sample_item();
+    my $transfer = $builder->build_object({ class => 'Koha::Item::Transfers', value => {
+        itemnumber => $item->id,
+        reason => 'StockrotationRepatriation',
+        datesent => undef,
+        frombranch => $item->homebranch,
+    }});
+    my @return = AddReturn( $item->barcode, $item->homebranch, 0, undef );
+    is_deeply(
+        \@return,
+        [ 0, { WasTransfered => $transfer->tobranch, TransferTrigger => 'StockrotationRepatriation', NotIssued => $item->barcode }, undef, {} ], "Item is reported to have been transferred");
+
+    $transfer->discard_changes;
+    ok( $transfer->datesent, 'The datesent field is populated, i.e. transfer is initiated');
+
+};
+
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
 $branches = Koha::Libraries->search();
index 8f8d796..59137b1 100644 (file)
@@ -590,6 +590,18 @@ sub _gen_default_values {
             materials          => undef,
             more_subfields_xml => undef,
         },
+        Branchtransfer => {
+            daterequested      => dt_from_string(),
+            datesent           => dt_from_string(),
+            datearrived        => undef,
+            datecancelled      => undef,
+            reason             => undef,
+            withdrawn          => 0,
+            restricted         => 0,
+            damaged            => 0,
+            materials          => undef,
+            more_subfields_xml => undef,
+        },
         Category => {
             enrolmentfee => 0,
             reservefee   => 0,