Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 12; |
|
|
23 |
use Test::MockModule; |
24 |
use Test::Warn; |
23 |
|
25 |
|
24 |
use C4::Circulation qw( MarkIssueReturned AddReturn ); |
26 |
use C4::Circulation qw( MarkIssueReturned AddReturn ); |
25 |
use Koha::Checkouts; |
27 |
use Koha::Checkouts; |
Lines 406-409
subtest 'automatic_checkin' => sub {
Link Here
|
406 |
is( dt_from_string($searched->returndate), $yesterday, 'old checkout for odue_ac_item has the right return date' ); |
408 |
is( dt_from_string($searched->returndate), $yesterday, 'old checkout for odue_ac_item has the right return date' ); |
407 |
|
409 |
|
408 |
$schema->storage->txn_rollback; |
410 |
$schema->storage->txn_rollback; |
409 |
} |
411 |
}; |
|
|
412 |
|
413 |
subtest 'attempt_auto_renew' => sub { |
414 |
|
415 |
plan tests => 17; |
416 |
|
417 |
$schema->storage->txn_begin; |
418 |
|
419 |
my $renew_error = 'auto_renew'; |
420 |
my $module = Test::MockModule->new('C4::Circulation'); |
421 |
$module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } ); |
422 |
my $around_now = dt_from_string(); |
423 |
$module->mock( 'AddRenewal', sub { warn "AddRenewal called" } ); |
424 |
my $checkout = $builder->build_object( |
425 |
{ |
426 |
class => 'Koha::Checkouts', |
427 |
value => { |
428 |
date_due => '2023-01-01 23:59:59', |
429 |
returndate => undef, |
430 |
auto_renew => 1, |
431 |
auto_renew_error => undef, |
432 |
onsite_checkout => 0, |
433 |
renewals_count => 0, |
434 |
} |
435 |
} |
436 |
); |
437 |
|
438 |
my ( $success, $error, $updated ); |
439 |
warning_is { |
440 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
441 |
} |
442 |
undef, "AddRenewal not called without confirm"; |
443 |
ok( $success, "Issue is renewed when error is 'auto_renew'" ); |
444 |
is( $error, undef, "No error when renewed" ); |
445 |
ok( $updated, "Issue reported as updated when renewed" ); |
446 |
|
447 |
warning_is { |
448 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
449 |
} |
450 |
"AddRenewal called", "AddRenewal called when confirm is passed"; |
451 |
ok( $success, "Issue is renewed when error is 'auto_renew'" ); |
452 |
is( $error, undef, "No error when renewed" ); |
453 |
ok( $updated, "Issue reported as updated when renewed" ); |
454 |
|
455 |
$renew_error = 'anything_else'; |
456 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
457 |
ok( !$success, "Success is untrue for any other status" ); |
458 |
is( $error, 'anything_else', "The error is passed through" ); |
459 |
ok( $updated, "Issue reported as updated when status changes" ); |
460 |
$checkout->discard_changes(); |
461 |
is( $checkout->auto_renew_error, undef, "Error not updated if confirm not passed" ); |
462 |
|
463 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
464 |
ok( !$success, "Success is untrue for any other status" ); |
465 |
is( $error, 'anything_else', "The error is passed through" ); |
466 |
ok( $updated, "Issue updated when confirm passed" ); |
467 |
$checkout->discard_changes(); |
468 |
is( $checkout->auto_renew_error, 'anything_else', "Error updated if confirm passed" ); |
469 |
|
470 |
# Error now equals 'anything_else' |
471 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
472 |
ok( !$updated, "Issue not reported as updated when status has not changed" ); |
473 |
|
474 |
$schema->storage->txn_rollback; |
475 |
}; |
410 |
- |
|
|