From 97b5df6080006f8e5cb4c86af577968a4df59f08 Mon Sep 17 00:00:00 2001 From: Lucas Gass Date: Thu, 21 Nov 2024 19:05:28 +0000 Subject: [PATCH] Bug 37334: Add filter_by_in_transit tests --- t/db_dependent/Koha/Items.t | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Items.t b/t/db_dependent/Koha/Items.t index b79db3ea3c..8f6520b31c 100755 --- a/t/db_dependent/Koha/Items.t +++ b/t/db_dependent/Koha/Items.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 21; +use Test::More tests => 22; use Test::MockModule; use Test::Exception; @@ -2254,3 +2254,50 @@ subtest 'filter_by_checked_out' => sub { $schema->storage->txn_rollback; }; + +subtest 'filter_by_in_transit' => sub { + plan tests => 3; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } ); + + my $library_1 = $builder->build( { source => 'Branch' } ); + my $library_2 = $builder->build( { source => 'Branch' } ); + + my $biblio = $builder->build_sample_biblio(); + my $item_1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, }); + my $item_2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber, }); + + is( $biblio->items->filter_by_in_transit->count, 0, "Filtered 0 in transit items" ); + + my $transfer_1 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item_1->itemnumber, + frombranch => $library_1->{branchcode}, + tobranch => $library_2->{branchcode}, + } + } + ); + + is( $biblio->items->filter_by_in_transit->count, 1, "Filtered 1 in transit items" ); + + my $transfer_2 = $builder->build_object( + { + class => 'Koha::Item::Transfers', + value => { + itemnumber => $item_2->itemnumber, + frombranch => $library_2->{branchcode}, + tobranch => $library_1->{branchcode}, + } + } + ); + + is( $biblio->items->filter_by_in_transit->count, 2, "Filtered 2 in transit items" ); + + $schema->storage->txn_rollback; + +}; -- 2.39.2