Bug 22891: Add tests

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
Jonathan Druart 2019-05-12 11:48:11 -05:00 committed by Nick Clemens
parent b41f215bfe
commit bc0d3e1a34
1 changed files with 36 additions and 1 deletions

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use CGI qw ( -utf8 );
use Test::More tests => 7;
use Test::More tests => 8;
use Test::MockModule;
use t::lib::Mocks;
use t::lib::TestBuilder;
@ -596,3 +596,38 @@ subtest 'GetRecords' => sub {
$schema->storage->txn_rollback;
};
subtest 'RenewHold' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $cgi = new CGI;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $item = $builder->build_object( { class => 'Koha::Items' } );
$cgi->param( patron_id => $patron->borrowernumber );
$cgi->param( item_id => $item->itemnumber );
t::lib::Mocks::mock_userenv( { patron => $patron } ); # For AddIssue
my $checkout = C4::Circulation::AddIssue( $patron->unblessed, $item->barcode );
# Everything is ok
my $reply = C4::ILSDI::Services::RenewLoan($cgi);
is( exists $reply->{date_due}, 1, 'If the item is checked out, the date_due key should exist' );
# The item is not checked out
$checkout->delete;
$reply = C4::ILSDI::Services::RenewLoan($cgi);
is( $reply, undef, 'If the item is not checked out, we should not explode.'); # FIXME We should return an error code instead
# The item does not exist
$item->delete;
$reply = C4::ILSDI::Services::RenewLoan($cgi);
is( $reply->{code}, 'RecordNotFound', 'If the item does not exist, RecordNotFound should be returned');
$patron->delete;
$reply = C4::ILSDI::Services::RenewLoan($cgi);
is( $reply->{code}, 'PatronNotFound', 'If the patron does not exist, PatronNotFound should be returned');
$schema->storage->txn_rollback;
};