From e4fc667d78872660ccf095a7f3bff7f109f1a476 Mon Sep 17 00:00:00 2001 From: Brendan Lawlor Date: Thu, 13 Mar 2025 20:13:05 +0000 Subject: [PATCH] Bug 38615: (follow-up) Unit tests Adds tests for the new HoldCancellationRequestSIP preference Test plan: 1. prove t/db_dependent/SIP/ILS.t 2. prove t/db_dependent/SIP/Transaction.t --- t/db_dependent/SIP/ILS.t | 30 ++++++++++- t/db_dependent/SIP/Transaction.t | 86 +++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/SIP/ILS.t b/t/db_dependent/SIP/ILS.t index a397cf19fb..d04c000b38 100755 --- a/t/db_dependent/SIP/ILS.t +++ b/t/db_dependent/SIP/ILS.t @@ -192,7 +192,7 @@ subtest cancel_hold => sub { }; subtest cancel_waiting_hold => sub { - plan tests => 7; + plan tests => 12; my $library = $builder->build_object( { class => 'Koha::Libraries' } ); my $patron = $builder->build_object( @@ -204,6 +204,7 @@ subtest cancel_waiting_hold => sub { } ); t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } ); + t::lib::Mocks::mock_preference( 'HoldCancellationRequestSIP', 0 ); my $item = $builder->build_sample_item( { @@ -252,6 +253,33 @@ subtest cancel_waiting_hold => sub { is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining" ); is( $item->holds->count(), 0, "Item has 0 holds remaining" ); + + t::lib::Mocks::mock_preference( 'HoldCancellationRequestSIP', 1 ); + + $reserve_id = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblio->biblionumber, + itemnumber => $item->itemnumber, + } + ); + $hold = Koha::Holds->find($reserve_id); + ok( $hold, 'Get hold object' ); + $hold->update( { found => 'W' } ); + $hold->get_from_storage; + + is( $hold->found, 'W', "Hold was correctly set to waiting." ); + + $transaction = $ils->cancel_hold( $patron->cardnumber, undef, $item->barcode, undef ); + + is( + $transaction->{screen_msg}, "Hold Cancellation Requested.", + "We get a success message when hold cancellation requested" + ); + + is( $item->biblio->holds->count(), 1, "Bib has 1 holds remaining" ); + is( $item->holds->count(), 1, "Item has 1 holds remaining" ); }; subtest checkout => sub { diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t index 1bee4c17e7..a07033def5 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 => 20; +use Test::More tests => 21; use Test::Warn; use DateTime; @@ -223,6 +223,90 @@ subtest cancel_hold => sub { is( $item->holds->count(), 0, "Item has 0 holds remaining" ); }; +subtest cancel_waiting_hold => sub { + plan tests => 14; + + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + } + } + ); + t::lib::Mocks::mock_userenv( { branchcode => $library->branchcode, flags => 1 } ); + t::lib::Mocks::mock_preference( 'HoldCancellationRequestSIP', 0 ); + + my $item = $builder->build_sample_item( + { + library => $library->branchcode, + } + ); + + Koha::CirculationRules->set_rules( + { + categorycode => $patron->categorycode, + branchcode => $library->branchcode, + itemtype => $item->effective_itemtype, + rules => { + onshelfholds => 1, + reservesallowed => 3, + holds_per_record => 3, + issuelength => 5, + lengthunit => 'days', + } + } + ); + + my $reserve_id = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblio->biblionumber, + itemnumber => $item->itemnumber, + } + ); + is( $item->biblio->holds->count(), 1, "Hold was placed on bib" ); + is( $item->holds->count(), 1, "Hold was placed on specific item" ); + + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); + my $transaction = C4::SIP::ILS::Transaction::Hold->new(); + is( ref $transaction, "C4::SIP::ILS::Transaction::Hold", "New transaction created" ); + is( $transaction->patron($sip_patron), $sip_patron, "Patron assigned to transaction" ); + is( $transaction->item($sip_item), $sip_item, "Item assigned to transaction" ); + my $hold = $transaction->drop_hold(); + is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining" ); + is( $item->holds->count(), 0, "Item has 0 holds remaining" ); + + t::lib::Mocks::mock_preference( 'HoldCancellationRequestSIP', 1 ); + + $reserve_id = AddReserve( + { + branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblio->biblionumber, + itemnumber => $item->itemnumber, + } + ); + + $hold = Koha::Holds->find($reserve_id); + ok( $hold, 'Get hold object' ); + $hold->update( { found => 'W' } ); + $hold->get_from_storage; + + is( $hold->found, 'W', "Hold was correctly set to waiting." ); + + $transaction = C4::SIP::ILS::Transaction::Hold->new(); + is( ref $transaction, "C4::SIP::ILS::Transaction::Hold", "New transaction created" ); + is( $transaction->patron($sip_patron), $sip_patron, "Patron assigned to transaction" ); + is( $transaction->item($sip_item), $sip_item, "Item assigned to transaction" ); + $hold = $transaction->drop_hold(); + is( $item->biblio->holds->count(), 1, "Bib has 1 holds remaining" ); + is( $item->holds->count(), 1, "Item has 1 holds remaining" ); +}; + subtest do_hold => sub { plan tests => 8; -- 2.39.5