Bug 31427: (follow-up) Unit tests

This patch adds a unit test for error precidence where autorenewals is
involved.

It is not comprehensive however, and I'm a little confused by the logic
around cron vs non-cron handling...

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit a71c21d2ff)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2023-10-26 09:08:04 +01:00 committed by Fridolin Somers
parent b14fe345dc
commit 8a62aa688a

View file

@ -431,7 +431,7 @@ subtest "GetIssuingCharges tests" => sub {
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
subtest "CanBookBeRenewed tests" => sub {
plan tests => 113;
plan tests => 114;
C4::Context->set_preference('ItemsDeniedRenewal','');
# Generate test biblio
@ -1011,6 +1011,49 @@ subtest "CanBookBeRenewed tests" => sub {
is( $renewokay, 1, 'No renewal before is 99, patron opted out of auto_renewal so can renew' );
$renewing_borrower_obj->autorenew_checkouts(1)->store;
# Bug 31427
# Ensure autorenewal errors always take highest precedence
subtest "auto_renewal errors first" => sub {
plan tests => 4;
my $auto_renew_item = $builder->build_sample_item(
{
biblionumber => $biblio->biblionumber,
library => $branch,
}
);
my $ten_days_ahead = dt_from_string->add( days => 10 );
my $issue = AddIssue(
$renewing_borrower_obj, $auto_renew_item->barcode, $ten_days_ahead, undef, undef, undef,
{ auto_renew => 1 }
);
Koha::CirculationRules->set_rules(
{
categorycode => undef,
branchcode => undef,
itemtype => undef,
rules => {
noautorenewalbefore => 7,
renewalsallowed => 2,
}
}
);
my ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 'cron' );
is( $renewokay, 0, 'Do not renew, renewal is automatic' );
is( $error, 'auto_too_soon', 'Cannot auto renew, too soon - returned code is auto_too_soon' );
$issue->renewals_count(2)->store;
( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrower_obj, $issue, undef, 'cron' );
is( $renewokay, 0, 'Do not renew, renewal is automatic' );
is(
$error, 'auto_too_soon',
'Cannot auto renew, too soon - auto renewal error takes precedence over non-autorenewal error too_many'
);
};
subtest "too_late_renewal / no_auto_renewal_after" => sub {
plan tests => 16;
my $item_to_auto_renew = $builder->build_sample_item(