From 6fe9657ec18dd8365c849e5a70c2e8e68f9a95e0 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 30 Aug 2023 18:29:27 +0000 Subject: [PATCH] Bug 34666: Unit test Signed-off-by: David Nind --- t/db_dependent/Reserves.t | 42 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t index 7e2d83e50e..c31a909fc2 100755 --- a/t/db_dependent/Reserves.t +++ b/t/db_dependent/Reserves.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 77; +use Test::More tests => 78; use Test::MockModule; use Test::Warn; @@ -30,6 +30,7 @@ use DateTime::Duration; use C4::Circulation qw( AddReturn AddIssue ); use C4::Items; use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); +use C4::HoldsQueue; use C4::Members; use C4::Reserves qw( AddReserve AlterPriority CheckReserves GetReservesControlBranch ModReserve ModReserveAffect ReserveSlip CalculatePriority CanReserveBeCanceledFromOpac CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); use Koha::ActionLogs; @@ -1773,3 +1774,42 @@ subtest 'DefaultHoldExpiration tests' => sub { $schema->txn_rollback; }; + +subtest '_Findgroupreserves' => sub { + plan tests => 1; + $schema->storage->txn_begin; + + my $patron_1 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $patron_2 = $builder->build_object( { class => 'Koha::Patrons' } ); + my $item = $builder->build_sample_item(); + + t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); + my $reserve_id_1 = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron_1->id, + biblionumber => $item->biblionumber, + } + ); + my $reserve_id_2 = AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron_2->id, + biblionumber => $item->biblionumber, + } + ); + + C4::HoldsQueue::AddToHoldTargetMap( + { + $item->id => { + borrowernumber => $patron_1->id, biblionumber => $item->biblionumber, + holdingbranch => $item->holdingbranch, item_level => 0, reserve_id => $reserve_id_1 + } + } + ); + + # When the hold is title level and in the hold fill targets we expect this to be the only hold returned + my @reserves = C4::Reserves::_Findgroupreserve( $item->biblionumber, $item->id, 0, [] ); + is( scalar @reserves, 1, "We should only get the hold that is in the map" ); + $schema->txn_rollback; +}; -- 2.30.2