From ad8e5df82f5c3e68a6a84ba65241e725b66ab7ab Mon Sep 17 00:00:00 2001 From: Emily Lamancusa Date: Mon, 8 Jan 2024 16:19:59 -0500 Subject: [PATCH] Bug 34972: Add unit tests for GetOtherReserves To test: 1. Apply this patch only 2. Prove -v t/db_dependent/Circulation.t --> Tests fail --> Note verbose output for Tests for GetOtherReserves: ok 3 - GetOtherReserves should not set found status not ok 4 - GetOtherReserves should not set itemnumber on biblio-level hold --> The itemnumber is set on a biblio-level hold, but the found status is not set! 3. Apply the other patch 4. Prove -v t/db_dependent/Circulation.t --> Tests pass --- t/db_dependent/Circulation.t | 69 +++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index f35af9d754..7ba50e0e12 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -18,7 +18,7 @@ use Modern::Perl; use utf8; -use Test::More tests => 70; +use Test::More tests => 71; use Test::Exception; use Test::MockModule; use Test::Deep qw( cmp_deeply ); @@ -6371,6 +6371,73 @@ subtest 'Test CanBookBeIssued param ignore_reserves (Bug 35322)' => sub { }; +subtest 'Tests for GetOtherReserves' => sub { + plan tests => 4; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron_1 = $builder->build_object( + { + class => 'Koha::Patrons', + } + ); + my $patron_2 = $builder->build_object( + { + class => 'Koha::Patrons', + } + ); + + # GetOtherReserves uses the ItemType object to check not-for-loan value + my $itype = $builder->build_object( + { + class => 'Koha::ItemTypes', + value => { + notforloan => 0, + } + } + ); + + my $item = $builder->build_object( + { + class => 'Koha::Items', + value => { + itype => $itype->itemtype, + homebranch => $library->branchcode, + } + } + ); + + t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode } ); + + my $reserve_1_id = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron_1->borrowernumber, + biblionumber => $item->biblionumber, + } + ); + + my $reserve_2_id = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron_2->borrowernumber, + biblionumber => $item->biblionumber, + } + ); + + my $messages; + my $nextreservinfo; + ( $messages, $nextreservinfo ) = GetOtherReserves( $item->itemnumber ); + + my $reserve_1 = Koha::Holds->search( { reserve_id => $reserve_1_id } )->next; + + is( + $nextreservinfo->{reserve_id}, $reserve_1->reserve_id, + 'GetOtherReserves should return the next reserve in line' + ); + is( $reserve_1->priority, 1, 'Next reserve in line should be priority 1' ); + ok( !$reserve_1->found, 'GetOtherReserves should not set found status' ); + ok( !$reserve_1->itemnumber, 'GetOtherReserves should not set itemnumber on a biblio-level hold' ); +}; $schema->storage->txn_rollback; C4::Context->clear_syspref_cache(); -- 2.34.1