From b66e95dea032b8306ffcae4250d6b2776733b30f Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Mon, 24 Nov 2025 12:59:21 +0000 Subject: [PATCH] Bug 15261: Add tests for overlapping reserves on ILS-DI --- t/db_dependent/ILSDI_Services.t | 129 +++++++++++++++++++++++++++++++- 1 file changed, 125 insertions(+), 4 deletions(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 369f629f8b..67422f28ca 100755 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -20,7 +20,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); use Test::NoWarnings; -use Test::More tests => 16; +use Test::More tests => 17; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; @@ -472,13 +472,23 @@ subtest 'Holds test' => sub { t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 0 ); + my $pickup_library = $builder->build_object( + { + class => 'Koha::Libraries', + value => { + pickup_location => 1, + } + } + ); + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); - my $item = $builder->build_sample_item( { damaged => 1 } ); + my $item = $builder->build_sample_item( { damaged => 1, library => $pickup_library->branchcode, } ); my $query = CGI->new; - $query->param( 'patron_id', $patron->borrowernumber ); - $query->param( 'bib_id', $item->biblionumber ); + $query->param( 'patron_id', $patron->borrowernumber ); + $query->param( 'bib_id', $item->biblionumber ); + $query->param( 'pickup_location', $pickup_library->branchcode ); my $reply = C4::ILSDI::Services::HoldTitle($query); is( $reply->{code}, 'damaged', "Item damaged" ); @@ -1263,3 +1273,114 @@ subtest 'Bug 34893: ILS-DI can return the wrong patron for AuthenticatePatron' = $schema->storage->txn_rollback; }; + +subtest 'Bug 23669: PreventReservesOnSamePeriod with ILS-DI' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + # Set up the test environment + t::lib::Mocks::mock_preference( 'PreventReservesOnSamePeriod', 1 ); + t::lib::Mocks::mock_preference( 'AllowHoldDateInFuture', 1 ); + + my $pickup_library = $builder->build_object( + { + class => 'Koha::Libraries', + value => { + pickup_location => 1, + } + } + ); + + # Create a patron + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + } + ); + + # Create a record and items + my $biblio = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item( + { + biblionumber => $biblio->biblionumber, + library => $pickup_library->branchcode, + } + ); + + Koha::CirculationRules->set_rule( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rule_name => 'reservesallowed', + rule_value => 99, + } + ); + + Koha::CirculationRules->set_rule( + { + categorycode => undef, + itemtype => undef, + branchcode => undef, + rule_name => 'holds_per_record', + rule_value => 99, + } + ); + + # Place an existing hold with specific dates + my $reserve_id = C4::Reserves::AddReserve( + { + branchcode => $item->homebranch, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => 1, + reservation_date => '2023-11-01', + expiration_date => '2023-11-10', + } + ); + + # Attempt to place a new hold with overlapping dates through ILS-DI + my $query = CGI->new; + $query->param( 'pickup_location', $pickup_library->branchcode ); + $query->param( 'patron_id', $patron->borrowernumber ); + $query->param( 'bib_id', $biblio->biblionumber ); + $query->param( 'start_date', '2023-11-05' ); + $query->param( 'expiry_date', '2023-11-15' ); + + my $reply = C4::ILSDI::Services::HoldTitle($query); + + # Verify that the hold is rejected + is( $reply->{code}, 'overlap', 'Hold is rejected due to overlapping dates' ); + + # Now try with non-overlapping dates + $query->param( 'start_date', '2023-11-15' ); + $query->param( 'expiry_date', '2023-11-20' ); + + $reply = C4::ILSDI::Services::HoldTitle($query); + + # Verify that the hold is accepted + is( $reply->{code}, undef, 'Hold is accepted with non-overlapping dates' ); + + # Test with item-level hold + $query->param( 'item_id', $item->itemnumber ); + $query->param( 'start_date', '2023-11-05' ); + $query->param( 'expiry_date', '2023-11-15' ); + + $reply = C4::ILSDI::Services::HoldItem($query); + + # Verify that the hold is rejected + is( $reply->{code}, 'overlap', 'Item-level hold is rejected due to overlapping dates' ); + + # Now try with non-overlapping dates + $query->param( 'start_date', '2023-11-25' ); + $query->param( 'expiry_date', '2023-11-30' ); + + $reply = C4::ILSDI::Services::HoldItem($query); + + # Verify that the hold is accepted + is( $reply->{code}, undef, 'Item-level hold is accepted with non-overlapping dates' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5