Bug 25755: Add Unit tests for update to get_transfer

We updated Koha::Item->get_transfer here to account for the new
daterequested field availability. It is now possible to set requested
without setting datesent simultaneiously.. as such we need to update
get_transfer to ensure we always return the right transfer (either the
one 'in transit' or the oldest request first.

This patch update the unit tests to test for this.

Signed-off-by: Kathleen Milne <kathleen.milne@cne-siar.gov.uk>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Joonas Kylmälä <joonas.kylmala@helsinki.fi>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Martin Renvoize 2020-09-18 14:56:23 +01:00 committed by Jonathan Druart
parent 17007f0345
commit f81ecbb19d
2 changed files with 56 additions and 9 deletions

View File

@ -462,8 +462,6 @@ Note: Transfers are retrieved in a Modified FIFO (First In First Out) order
whereby the most recently sent, but not recieved, transfer will be returned
if it exists, otherwise the oldest unsatisfied transfer will be returned.
FIXME: Add Tests for FIFO functionality
=cut
sub get_transfer {

View File

@ -1184,23 +1184,72 @@ subtest 'store' => sub {
};
subtest 'get_transfer' => sub {
plan tests => 3;
plan tests => 6;
my $transfer = $new_item_1->get_transfer();
is( $transfer, undef, 'Koha::Item->get_transfer should return undef if the item is not in transit' );
my $library_to = $builder->build( { source => 'Branch' } );
C4::Circulation::transferbook({
from_branch => $new_item_1->holdingbranch,
to_branch => $library_to->{branchcode},
barcode => $new_item_1->barcode,
});
my $transfer_1 = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
itemnumber => $new_item_1->itemnumber,
frombranch => $new_item_1->holdingbranch,
tobranch => $library_to->{branchcode},
reason => 'Manual',
datesent => undef,
datearrived => undef,
daterequested => \'NOW()'
}
}
);
$transfer = $new_item_1->get_transfer();
is( ref($transfer), 'Koha::Item::Transfer', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' );
is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer should return a valid Koha::Item::Transfers object' );
my $transfer_2 = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
itemnumber => $new_item_1->itemnumber,
frombranch => $new_item_1->holdingbranch,
tobranch => $library_to->{branchcode},
reason => 'Manual',
datesent => undef,
datearrived => undef,
daterequested => \'NOW()'
}
}
);
$transfer = $new_item_1->get_transfer();
is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the oldest transfer request');
$transfer_2->datesent(\'NOW()')->store;
$transfer = $new_item_1->get_transfer();
is( $transfer->branchtransfer_id, $transfer_2->branchtransfer_id, 'Koha::Item->get_transfer returns the in_transit transfer');
my $transfer_3 = $builder->build_object(
{
class => 'Koha::Item::Transfers',
value => {
itemnumber => $new_item_1->itemnumber,
frombranch => $new_item_1->holdingbranch,
tobranch => $library_to->{branchcode},
reason => 'Manual',
datesent => undef,
datearrived => undef,
daterequested => \'NOW()'
}
}
);
$transfer_2->datearrived(\'NOW()')->store;
$transfer = $new_item_1->get_transfer();
is( $transfer->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfer returns the next queued transfer');
is( $transfer->itemnumber, $new_item_1->itemnumber, 'Koha::Item->get_transfer returns the right items transfer' );
};
subtest 'holds' => sub {