Bug 24620: Unit tests
authorNick Clemens <nick@bywatersolutions.com>
Mon, 10 Feb 2020 18:18:45 +0000 (18:18 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 14 Apr 2020 16:24:41 +0000 (17:24 +0100)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
t/db_dependent/Circulation.t

index d0c97ec..1ca01ea 100755 (executable)
@@ -18,7 +18,7 @@
 use Modern::Perl;
 use utf8;
 
-use Test::More tests => 47;
+use Test::More tests => 48;
 use Test::MockModule;
 use Test::Deep qw( cmp_deeply );
 
@@ -40,8 +40,10 @@ use C4::Overdues qw(UpdateFine CalcFine);
 use Koha::DateUtils;
 use Koha::Database;
 use Koha::Items;
+use Koha::Item::Transfers;
 use Koha::Checkouts;
 use Koha::Patrons;
+use Koha::Holds;
 use Koha::CirculationRules;
 use Koha::Subscriptions;
 use Koha::Account::Lines;
@@ -3813,6 +3815,44 @@ subtest 'Do not return on renewal (LOST charge)' => sub {
     );
 };
 
+subtest 'Filling a hold should cancel existing transfer' => sub {
+    plan tests => 4;
+
+    t::lib::Mocks::mock_preference('AutomaticItemReturn', 1);
+
+    my $libraryA = $builder->build_object( { class => 'Koha::Libraries' } )->store;
+    my $libraryB = $builder->build_object( { class => 'Koha::Libraries' } )->store;
+    my $patron = $builder->build_object(
+        {
+            class => 'Koha::Patrons',
+            value => {
+                categorycode => $patron_category->{categorycode},
+                branchcode => $libraryA->branchcode,
+            }
+        }
+    )->store;
+
+    my $item = $builder->build_sample_item({
+        homebranch => $libraryB->branchcode,
+    });
+
+    my ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef );
+    is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 1, "We generate a transfer on checkin");
+    AddReserve(
+        $libraryA->branchcode, $patron->borrowernumber, $item->biblionumber, '',
+        1, undef, undef, '',
+        undef, $item->itemnumber, undef, undef
+    );
+    my $reserves = Koha::Holds->search({ itemnumber => $item->itemnumber });
+    is( $reserves->count, 1, "Reserve is placed");
+    ( undef, $message ) = AddReturn( $item->barcode, $libraryA->branchcode, undef, undef );
+    my $reserve = $reserves->next;
+    ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 0, $reserve->reserve_id );
+    $reserve->discard_changes;
+    ok( $reserve->found eq 'W', "Reserve is marked waiting" );
+    is( Koha::Item::Transfers->search({ itemnumber => $item->itemnumber, datearrived => undef })->count, 0, "No outstanding transfers when hold is waiting");
+};
+
 $schema->storage->txn_rollback;
 C4::Context->clear_syspref_cache();
 $cache->clear_from_cache('single_holidays');