From 609147915c17538963c3a35b57bd5faa75f8e7e7 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 12 May 2025 14:49:26 +0100 Subject: [PATCH] Bug 39820: (QA follow-up) Unit tests This patch adds unit tests.. but it also adds some FIXME and QUESTION statements to those tests --- t/db_dependent/SIP/Transaction.t | 74 +++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index a07033def5b..8482d3c3ce1 100755 --- a/t/db_dependent/SIP/Transaction.t +++ b/t/db_dependent/SIP/Transaction.t @@ -5,7 +5,7 @@ use Modern::Perl; use Test::NoWarnings; -use Test::More tests => 21; +use Test::More tests => 22; use Test::Warn; use DateTime; @@ -710,6 +710,78 @@ subtest do_checkin => sub { }; }; +subtest 'cancel_waiting_holds_with_cancellation_requests at checkin' => sub { + plan tests => 5; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron1 = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + + t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } ); + + my $item = $builder->build_sample_item( + { + library => $library->branchcode, + } + ); + + # Set up a hold for patron1 + my $hold = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron1->borrowernumber, + biblionumber => $item->biblio->biblionumber, + itemnumber => $item->itemnumber, + } + ); + + # Mark the hold as waiting + my $hold_obj = Koha::Holds->find($hold); + $hold_obj->update( { found => 'W' } )->store(); + + # Add a cancellation request for the hold + my $cancellation_request = Koha::Hold::CancellationRequest->new( + { + hold_id => $hold_obj->id, + creation_date => \'NOW()', + } + )->store; + + is( + $item->holds->waiting->filter_by_has_cancellation_requests->count, 1, + 'Hold has a cancellation request' + ); + + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); + my $transaction = C4::SIP::ILS::Transaction::Checkin->new(); + + $transaction->item($sip_item); + $transaction->do_checkin( $library->branchcode, C4::SIP::Sip::timestamp ); + + # Check if the hold still exists + $hold_obj = Koha::Holds->find($hold); + ok( !defined( $hold_obj ), 'Hold has been cancelled and deleted' ); + + my $old_hold = Koha::Old::Holds->find($hold); + ok( $old_hold, 'Hold was moved to old reserves'); + # QUESTION: Should the cancellation reason be set to "Cancelled by SIP"? + is( $old_hold->cancellation_reason, undef, 'No cancellation reason was set' ); + + # FIXME: What should happen to the cancellation request? + # Check that the cancellation request is deleted + # my $existing_cancellation_requests = Koha::Hold::CancellationRequests->search( { hold_id => $hold } ); + # is( $existing_cancellation_requests->count, 0, 'Cancellation request is deleted after processing' ); + + # Verify the item's hold count + is( $item->holds->count, 0, 'No holds remain on the item after cancellation' ); +}; + subtest do_checkout_with_sysprefs_override => sub { plan tests => 8; -- 2.49.0