From 04129dc9415683ec938db718077cfd3100ad4500 Mon Sep 17 00:00:00 2001 From: Laura_Escamilla Date: Thu, 16 Oct 2025 14:07:51 +0000 Subject: [PATCH] Bug 39204: Unit test --- t/db_dependent/Koha/Hold.t | 81 +++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t index 22b8ddbb14..997ea189fd 100755 --- a/t/db_dependent/Koha/Hold.t +++ b/t/db_dependent/Koha/Hold.t @@ -1264,7 +1264,7 @@ subtest 'strings_map() tests' => sub { subtest 'revert_found() tests' => sub { - plan tests => 6; + plan tests => 7; subtest 'item-level holds tests' => sub { @@ -1592,6 +1592,85 @@ subtest 'revert_found() tests' => sub { $schema->storage->txn_rollback; }; + subtest 'SIP do_hold/drop_hold regression: item-level visibility and cancel' => sub { + + plan tests => 6; + $schema->storage->txn_begin; + + use C4::Reserves qw(AddReserve); + use Test::MockModule; + + my $letters_mock = Test::MockModule->new('C4::Letters'); + $letters_mock->mock( 'GetPreparedLetter', sub { return { content => '', title => '' } } ); + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $branch = $library->branchcode; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my $biblio = $builder->build_sample_biblio( { title => 'SIP regression test' } ); + my $item = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); + my $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ); + AddReserve( + { + branchcode => $branch, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + priority => $priority, + } + ); + + my $holds_via_item_title = $item->holds->search( { borrowernumber => $patron->borrowernumber } ); + is( + $holds_via_item_title->count, 0, + 'Title-level hold is NOT visible via item->holds (expected baseline)' + ); + + my $title_hold = Koha::Holds->search( + { borrowernumber => $patron->borrowernumber, biblionumber => $biblio->biblionumber, itemnumber => undef } ) + ->next; + ok( $title_hold, 'Title-level hold created' ); + + if ( $title_hold->can('cancel') ) { + $title_hold->cancel( { cancellation_reason => 'TEST' } ); + } else { + $title_hold->delete; + } + ok( !Koha::Holds->find( $title_hold->id ), 'Title-level hold canceled (cleanup)' ); + + $priority = C4::Reserves::CalculatePriority( $biblio->biblionumber ); + AddReserve( + { + branchcode => $branch, + borrowernumber => $patron->borrowernumber, + biblionumber => $biblio->biblionumber, + itemnumber => $item->itemnumber, + priority => $priority, + } + ); + + my $holds_via_item = $item->holds->search( { borrowernumber => $patron->borrowernumber } ); + is( + $holds_via_item->count, 1, + 'Item-level hold IS visible via item->holds (SIP drop_hold depends on this)' + ); + my $item_hold = $holds_via_item->next; + ok( $item_hold && $item_hold->id, 'Have the specific item-level hold object' ); + if ( $item_hold->can('cancel') ) { + $item_hold->cancel( { cancellation_reason => 'TEST' } ); + } else { + $item_hold->delete; + } + ok( + !Koha::Holds->find( $item_hold->id ), + 'Item-level hold canceled successfully (mirrors SIP drop_hold behavior)' + ); + + $letters_mock->unmock_all; + + $schema->storage->txn_rollback; + }; + subtest 'desk_id handling tests' => sub { plan tests => 12; -- 2.39.5