Bug 23695: (follow-up) Adjust for addition of transfer trigger

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Nick Clemens 2020-03-23 12:46:26 +00:00 committed by Jonathan Druart
parent f3c66c6d94
commit 4d0e22f97a
2 changed files with 75 additions and 36 deletions

View file

@ -18,7 +18,7 @@
use Modern::Perl;
use utf8;
use Test::More tests => 50;
use Test::More tests => 49;
use Test::MockModule;
use Test::Deep qw( cmp_deeply );
@ -3296,31 +3296,6 @@ subtest 'Cancel transfers on lost items' => sub {
};
subtest 'transferbook test' => sub {
plan tests => 5;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $item = $builder->build_sample_item();
ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
C4::Circulation::transferbook({
from_branch => $library->branchcode,
to_branch => $item->homebranch,
barcode => $item->barcode,
});
my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
C4::Circulation::transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode,
});
($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
};
subtest 'CanBookBeIssued | is_overdue' => sub {
plan tests => 3;

View file

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 5;
use Test::More tests => 6;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -39,7 +39,11 @@ subtest 'transfer a non-existant item' => sub {
$item->delete;
my ( $dotransfer, $messages ) =
C4::Circulation::transferbook( $library->{branchcode}, $badbc );
C4::Circulation::transferbook({
from_branch => $item->homebranch,
to_branch => $library->{branchcode},
barcode => $badbc
});
is( $dotransfer, 0, "Can't transfer a bad barcode" );
is_deeply(
$messages,
@ -70,7 +74,12 @@ subtest 'field population tests' => sub {
);
my $trigger = "Manual";
my ($dotransfer, $messages ) = transferbook( $library2->branchcode, $item->barcode, undef, $trigger );
my ($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library2->branchcode,
barcode => $item->barcode,
trigger => $trigger
});
is( $dotransfer, 1, 'Transfer succeeded' );
is_deeply(
$messages,
@ -108,7 +117,11 @@ subtest 'transfer already at destination' => sub {
}
);
my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
my ($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode
});
is( $dotransfer, 0, 'Transfer of item failed when destination equals holding branch' );
is_deeply(
$messages,
@ -126,7 +139,11 @@ subtest 'transfer already at destination' => sub {
itemnumber => $item->itemnumber,
});
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode
});
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
@ -157,7 +174,11 @@ subtest 'transfer an issued item' => sub {
# We are making sure there is no regression, feel free to change the behavior if needed.
# * WasReturned does not seem like a variable that should contain a borrowernumber
# * Should we return even if the transfer did not happen? (same branches)
my ($dotransfer, $messages) = transferbook( $library->branchcode, $item->barcode );
my ($dotransfer, $messages) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode
});
is( $messages->{WasReturned}, $patron->borrowernumber, 'transferbook should have return a WasReturned flag is the item was issued before the transferbook call');
# Reset issue
@ -173,7 +194,11 @@ subtest 'transfer an issued item' => sub {
itemnumber => $item->itemnumber,
});
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode
});
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
@ -208,19 +233,33 @@ subtest 'ignore_reserves flag' => sub {
# We are making sure there is no regression, feel free to change the behavior if needed.
# * Contrary to the POD, if ignore_reserves is not passed (or is false), any item reserve
# found will override all other measures that may prevent transfer and force a transfer.
my ($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode );
my ($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode
});
is( $dotransfer, 1, 'Transfer of reserved item succeeded without ignore reserves' );
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
my $ignore_reserves = 0;
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves );
($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode,
ignore_reserves => $ignore_reserves
});
is( $dotransfer, 1, 'Transfer of reserved item succeeded with ignore reserves: false' );
is( $messages->{ResFound}->{ResFound}, 'Reserved', "We found the reserve");
is( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We got the reserve info");
$ignore_reserves = 1;
($dotransfer, $messages ) = transferbook( $library->branchcode, $item->barcode, $ignore_reserves );
($dotransfer, $messages ) = transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode,
ignore_reserves => $ignore_reserves
});
is( $dotransfer, 0, 'Transfer of reserved item failed with ignore reserves: true' );
is_deeply(
$messages,
@ -230,3 +269,28 @@ subtest 'ignore_reserves flag' => sub {
isnt( $messages->{ResFound}->{ResFound}, 'Reserved', "We did not return that we found a reserve");
isnt( $messages->{ResFound}->{itemnumber}, $item->itemnumber, "We did not return the reserve info");
};
subtest 'transferbook test from branch' => sub {
plan tests => 5;
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
my $item = $builder->build_sample_item();
ok( $item->holdingbranch ne $library->branchcode && $item->homebranch ne $library->branchcode, "Item is not held or owned by library");
C4::Circulation::transferbook({
from_branch => $library->branchcode,
to_branch => $item->homebranch,
barcode => $item->barcode,
});
my ($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
is( $from_branch, $library->branchcode, 'The transfer is initiated from the specified branch, not the items home or holdingbranch');
is( $to_branch, $item->homebranch, 'The transfer is initiated to the specified branch');
C4::Circulation::transferbook({
from_branch => $item->homebranch,
to_branch => $library->branchcode,
barcode => $item->barcode,
});
($datesent,$from_branch,$to_branch) = GetTransfers($item->itemnumber);
is( $from_branch, $item->homebranch, 'The transfer is initiated from the specified branch');
is( $to_branch, $library->branchcode, 'The transfer is initiated to the specified branch');
};