From dcb8aff8b24ae6337fdd299a373eab52310c517a Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Mon, 27 Jan 2020 05:41:05 +0100 Subject: [PATCH] Bug 22379: Unit tests for CancelHold service Signed-off-by: Martin Renvoize --- t/db_dependent/ILSDI_Services.t | 62 ++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ILSDI_Services.t b/t/db_dependent/ILSDI_Services.t index 4e525899eb..0824f9cdec 100755 --- a/t/db_dependent/ILSDI_Services.t +++ b/t/db_dependent/ILSDI_Services.t @@ -19,7 +19,7 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use Test::More tests => 11; +use Test::More tests => 12; use Test::MockModule; use t::lib::Mocks; use t::lib::TestBuilder; @@ -28,6 +28,7 @@ use XML::LibXML; use C4::Items qw( ModItemTransfer ); use C4::Circulation qw( AddIssue ); +use C4::Reserves qw (AddReserve ModReserve ModReserveAffect ModReserveStatus); use Koha::AuthUtils; use Koha::DateUtils qw( dt_from_string ); @@ -738,6 +739,65 @@ subtest 'RenewHold' => sub { $schema->storage->txn_rollback; }; +subtest 'CancelHold' => sub { + plan tests => 4; + + $schema->storage->txn_begin; + + my $cgi = CGI->new; + + my $library = $builder->build_object({ + class => 'Koha::Libraries', + }); + + my $patron = $builder->build_object( { class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + }, + } ); + + my $patron2 = $builder->build_object( { class => 'Koha::Patrons', + value => { + branchcode => $library->branchcode, + }, + } ); + + my $item = $builder->build_sample_item({ library => $library->branchcode }); + + my $reserve = C4::Reserves::AddReserve({branchcode => $library->branchcode, + borrowernumber => $patron->borrowernumber, + biblionumber => $item->biblionumber }); + + # Affecting the reserve sets it to a waiting state + C4::Reserves::ModReserveAffect( $item->itemnumber, + $patron->borrowernumber, + undef, + $reserve, + ); + + $cgi->param( patron_id => $patron2->borrowernumber ); + $cgi->param( item_id => $reserve ); + + + my $reply = C4::ILSDI::Services::CancelHold($cgi); + is( $reply->{code}, 'BorrowerCannotCancelHold', 'If the patron is wrong, BorrowerCannotCancelHold should be returned'); + + $cgi->param( patron_id => $patron->borrowernumber ); + $reply = C4::ILSDI::Services::CancelHold($cgi); + is( $reply->{code}, 'BorrowerCannotCancelHold', 'If reserve in a Waiting state, patron cannot cancel'); + + C4::Reserves::ModReserveStatus( $item->itemnumber, 'T' ); + $reply = C4::ILSDI::Services::CancelHold($cgi); + is( $reply->{code}, 'BorrowerCannotCancelHold', 'If reserve in a Transfer state, patron cannot cancel'); + + C4::Reserves::ModReserve( {rank => 1, reserve_id => $reserve, branchcode => $library->branchcode} ); + $cgi->param( item_id => $reserve ); + $reply = C4::ILSDI::Services::CancelHold($cgi); + is( $reply->{code}, 'Canceled', 'If the patron is fine and reserve not waiting, Canceled should be returned and reserve canceled'); + + $schema->storage->txn_rollback; +}; + subtest 'GetPatronInfo paginated loans' => sub { plan tests => 7; -- 2.20.1