Browse Source

Bug 23207: Regression tests

This patch introduces a regression test for the case the automatic
checkin happens after the date due. In that case the item souldn't
really be overdue, and the checkin should be recorded with the date due
as return date.

To test:
1. Apply this patch
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Checkouts.t
=> FAIL: The feature doesn't behave correctly

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
21.05.x
Tomás Cohen Arazi 3 years ago
committed by Jonathan Druart
parent
commit
78f6bb6fa1
  1. 52
      t/db_dependent/Koha/Checkouts.t

52
t/db_dependent/Koha/Checkouts.t

@ -262,41 +262,62 @@ subtest 'Koha::Old::Checkouts->filter_by_todays_checkins' => sub {
$schema->storage->txn_rollback;
subtest 'automatic_checkin' => sub {
plan tests => 6;
plan tests => 9;
$schema->storage->txn_begin;
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
my $due_ac_item =
$builder->build_sample_item( { homebranch => $patron->branchcode } );
$builder->build_sample_item(
{ homebranch => $patron->branchcode, itemlost => 0 } );
my $ac_item =
$builder->build_sample_item( { homebranch => $patron->branchcode } );
$builder->build_sample_item(
{ homebranch => $patron->branchcode, itemlost => 0 } );
my $odue_ac_item =
$builder->build_sample_item(
{ homebranch => $patron->branchcode, itemlost => 0 } );
my $normal_item =
$builder->build_sample_item( { homebranch => $patron->branchcode } );
$builder->build_sample_item(
{ homebranch => $patron->branchcode, itemlost => 0 } );
$due_ac_item->itemtype->automatic_checkin(1)->store;
$odue_ac_item->itemtype->automatic_checkin(1)->store;
$ac_item->itemtype->automatic_checkin(1)->store;
$normal_item->itemtype->automatic_checkin(0)->store;
my $current_date = dt_from_string;
my $today = dt_from_string;
my $tomorrow = dt_from_string->add( days => 1 );
my $yesterday = dt_from_string->subtract( days => 1 );
# due checkout for automatic checkin
# Checkout do for automatic checkin
my $checkout_due_aci = Koha::Checkout->new(
{
borrowernumber => $patron->borrowernumber,
itemnumber => $due_ac_item->itemnumber,
branchcode => $patron->branchcode,
date_due => $current_date,
date_due => $today,
}
)->store;
# Checkout not due for automatic checkin
my $checkout_odue_aci = Koha::Checkout->new(
{
borrowernumber => $patron->borrowernumber,
itemnumber => $odue_ac_item->itemnumber,
branchcode => $patron->branchcode,
date_due => $yesterday
}
)->store;
# in time checkout for automatic checkin
# Checkout not due for automatic checkin
my $checkout_aci = Koha::Checkout->new(
{
borrowernumber => $patron->borrowernumber,
itemnumber => $ac_item->itemnumber,
branchcode => $patron->branchcode,
date_due => $tomorrow
}
)->store;
@ -306,7 +327,7 @@ subtest 'automatic_checkin' => sub {
borrowernumber => $patron->borrowernumber,
itemnumber => $normal_item->itemnumber,
branchcode => $patron->branchcode,
date_due => $current_date,
date_due => $today,
}
)->store;
@ -325,6 +346,13 @@ subtest 'automatic_checkin' => sub {
'checkout for due_ac_item exists'
);
$searched = Koha::Checkouts->find( $checkout_odue_aci->issue_id );
is(
$searched->issue_id,
$checkout_odue_aci->issue_id,
'checkout for odue_ac_item exists'
);
Koha::Checkouts->automatic_checkin;
$searched = Koha::Checkouts->find( $checkout_ni->issue_id );
@ -338,5 +366,11 @@ subtest 'automatic_checkin' => sub {
$searched = Koha::Checkouts->find( $checkout_due_aci->issue_id );
is( $searched, undef, 'checkout for due_ac_item doesn\'t exist anymore' );
$searched = Koha::Checkouts->find( $checkout_odue_aci->issue_id );
is( $searched, undef, 'checkout for odue_ac_item doesn\'t exist anymore' );
$searched = Koha::Old::Checkouts->find( $checkout_odue_aci->issue_id );
is( dt_from_string($searched->returndate), $yesterday, 'old checkout for odue_ac_item has the right return date' );
$schema->storage->txn_rollback;
}

Loading…
Cancel
Save