Bug 12630: Rebase tests and cover CheckReserves

It turns out we do honor reservedate in CheckReserves, so a hold with a lower priority will
fill before a hold in the future. I add tests to cover this and fix the old tests to pass again

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit a1739ea43b)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 12b90bb02f)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
This commit is contained in:
Nick Clemens 2022-06-10 14:47:44 +00:00 committed by Arthur Suzuki
parent 95f1902700
commit ba3d9d51de
2 changed files with 47 additions and 12 deletions

View File

@ -225,7 +225,7 @@ sub AddReserve {
}
}
if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
# Make room in reserves for this before those of a later reserve date
# Make room in reserves for this if passed a priority
$priority = _ShiftPriority( $biblionumber, $priority );
}

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 75;
use Test::More tests => 73;
use Test::MockModule;
use Test::Warn;
@ -387,8 +387,29 @@ t::lib::Mocks::mock_preference('ConfirmFutureHolds', 7);
($doreturn, $messages)= AddReturn('97531',$branch_1);
is(exists $messages->{ResFound}?1:0, 1, 'AddReturn considers future reserve within ConfirmFutureHolds days');
my $now_holder = $builder->build_object({ class => 'Koha::Patrons', value => {
branchcode => $branch_1,
}});
my $now_reserve_id = AddReserve(
{
branchcode => $branch_1,
borrowernumber => $requesters{$branch_1},
biblionumber => $bibnum,
priority => 2,
reservation_date => output_pref(dt_from_string()),
}
);
my $which_highest;
($status,$which_highest)=CheckReserves($item->itemnumber,undef,3);
is( $which_highest->{reserve_id}, $now_reserve_id, 'CheckReserves returns lower priority current reserve with insufficient lookahead');
($status, $which_highest)=CheckReserves($item->itemnumber,undef,4);
is( $which_highest->{reserve_id}, $reserve_id, 'CheckReserves returns higher priority future reserve with sufficient lookahead');
ModReserve({ reserve_id => $now_reserve_id, rank => 'del', cancellation_reason => 'test reserve' });
# End of tests for bug 9761 (ConfirmFutureHolds)
# test marking a hold as captured
my $hold_notice_count = count_hold_print_messages();
ModReserveAffect($item->itemnumber, $requesters{$branch_1}, 0);
@ -521,26 +542,40 @@ is($p, 3, 'CalculatePriority should now return priority 3');
# regression test for bug 12630
# Now there are 2 reserves on $bibnum
t::lib::Mocks::mock_preference('AllowHoldDateInFuture', 1);
my $borrowernumber_tmp_1 = AddMember(
my $bor_tmp_1 = $builder->build_object({ class => 'Koha::Patrons',value =>{
firstname => 'my firstname tmp 1',
surname => 'my surname tmp 1',
categorycode => 'S',
branchcode => 'CPL',
);
my $borrowernumber_tmp_2 = AddMember(
}});
my $bor_tmp_2 = $builder->build_object({ class => 'Koha::Patrons',value =>{
firstname => 'my firstname tmp 2',
surname => 'my surname tmp 2',
categorycode => 'S',
branchcode => 'CPL',
);
}});
my $borrowernumber_tmp_1 = $bor_tmp_1->borrowernumber;
my $borrowernumber_tmp_2 = $bor_tmp_2->borrowernumber;
my $date_in_future = dt_from_string();
$date_in_future = $date_in_future->add_duration(DateTime::Duration->new(days => 1));
AddReserve('CPL', $borrowernumber_tmp_1, $bibnum, undef, undef, 3, output_pref($date_in_future));
AddReserve('CPL', $borrowernumber_tmp_2, $bibnum, undef, undef, 4);
my @r1 = GetReservesFromBorrowernumber( $borrowernumber_tmp_1 );
my @r2 = GetReservesFromBorrowernumber( $borrowernumber_tmp_2 );
is( $r1[0]->{priority}, 3, 'priority for hold in future should be correct');
is( $r2[0]->{priority}, 4, 'priority for hold not in future should be correct');
AddReserve({
branch => 'CPL',
borrowernumber => $borrowernumber_tmp_1,
biblionumber => $bibnum,
priority => 3,
reservation_date => output_pref($date_in_future)
});
AddReserve({
branch => 'CPL',
borrowernumber => $borrowernumber_tmp_2,
biblionumber => $bibnum,
priority => 4,
reservation_date => output_pref($date_in_future)
});
my @r1 = Koha::Holds->search({ borrowernumber => $borrowernumber_tmp_1 })->as_list;
my @r2 = Koha::Holds->search({ borrowernumber => $borrowernumber_tmp_2 })->as_list;
is( $r1[0]->priority, 3, 'priority for hold in future should be correct');
is( $r2[0]->priority, 4, 'priority for hold not in future should be correct');
# end of tests for bug 12630
# Tests for cancel reserves by users from OPAC.