From f938e5f25935c44d80710c16378db27e64597909 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 26 May 2021 11:13:44 -0400 Subject: [PATCH] Bug 28464: Add unit tests --- t/db_dependent/SIP/ILS.t | 66 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/SIP/ILS.t b/t/db_dependent/SIP/ILS.t index 99c0df2147..971fb2c6d5 100755 --- a/t/db_dependent/SIP/ILS.t +++ b/t/db_dependent/SIP/ILS.t @@ -20,16 +20,17 @@ use Modern::Perl; -use Test::More tests => 11; +use Test::More tests => 12; use t::lib::TestBuilder; use t::lib::Mocks; -use C4::Reserves; use C4::Circulation; +use C4::Reserves; use Koha::CirculationRules; use Koha::Database; use Koha::DateUtils; +use Koha::Holds; BEGIN { use_ok('C4::SIP::ILS'); @@ -125,6 +126,67 @@ subtest cancel_hold => sub { is( $item->holds->count(), 0, "Item has 0 holds remaining"); }; +subtest cancel_waiting_hold => sub { + plan tests => 7; + + 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 }); + + 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 $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." ); + + my $ils = C4::SIP::ILS->new({ id => $library->branchcode }); + my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + my $transaction = $ils->cancel_hold($patron->cardnumber,undef,$item->barcode,undef); + + is( $transaction->{screen_msg},"Hold Cancelled.","We get a success message when hold cancelled"); + + is( $item->biblio->holds->count(), 0, "Bib has 0 holds remaining"); + is( $item->holds->count(), 0, "Item has 0 holds remaining"); +}; + subtest checkout => sub { plan tests => 4; -- 2.30.1 (Apple Git-130)