Lines 487-501
subtest 'automatic_checkin' => sub {
Link Here
|
487 |
|
487 |
|
488 |
subtest 'attempt_auto_renew' => sub { |
488 |
subtest 'attempt_auto_renew' => sub { |
489 |
|
489 |
|
490 |
plan tests => 17; |
490 |
plan tests => 33; |
491 |
|
491 |
|
492 |
$schema->storage->txn_begin; |
492 |
$schema->storage->txn_begin; |
493 |
|
493 |
|
494 |
my $renew_error = 'auto_renew'; |
494 |
my $renew_error = 'auto_renew'; |
495 |
my $module = Test::MockModule->new('C4::Circulation'); |
495 |
my $module = Test::MockModule->new('C4::Circulation'); |
496 |
$module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } ); |
496 |
$module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } ); |
497 |
my $around_now = dt_from_string(); |
497 |
$module->mock( 'AddRenewal', sub { warn "AddRenewal called" } ); |
498 |
$module->mock( 'AddRenewal', sub { warn "AddRenewal called" } ); |
|
|
499 |
my $checkout = $builder->build_object( |
498 |
my $checkout = $builder->build_object( |
500 |
{ |
499 |
{ |
501 |
class => 'Koha::Checkouts', |
500 |
class => 'Koha::Checkouts', |
Lines 527-532
subtest 'attempt_auto_renew' => sub {
Link Here
|
527 |
is( $error, undef, "No error when renewed" ); |
526 |
is( $error, undef, "No error when renewed" ); |
528 |
ok( $updated, "Issue reported as updated when renewed" ); |
527 |
ok( $updated, "Issue reported as updated when renewed" ); |
529 |
|
528 |
|
|
|
529 |
$module->mock( 'AddRenewal', sub { return; } ); |
530 |
|
530 |
$renew_error = 'anything_else'; |
531 |
$renew_error = 'anything_else'; |
531 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
532 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
532 |
ok( !$success, "Success is untrue for any other status" ); |
533 |
ok( !$success, "Success is untrue for any other status" ); |
Lines 546-550
subtest 'attempt_auto_renew' => sub {
Link Here
|
546 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
547 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
547 |
ok( !$updated, "Issue not reported as updated when status has not changed" ); |
548 |
ok( !$updated, "Issue not reported as updated when status has not changed" ); |
548 |
|
549 |
|
|
|
550 |
$renew_error = "auto_unseen_final"; |
551 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
552 |
ok( $success, "Issue is renewed when error is 'auto_unseen_final'" ); |
553 |
is( $error, 'auto_unseen_final', "Error of finality reported when renewed" ); |
554 |
ok( $updated, "Issue reported as updated when renewed" ); |
555 |
$checkout->discard_changes(); |
556 |
is( $checkout->auto_renew_error, 'auto_unseen_final', "Error updated" ); |
557 |
|
558 |
$renew_error = "too_unseen"; |
559 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
560 |
ok( !$success, "Issue is not renewed when error is 'too_unseen'" ); |
561 |
is( $error, 'too_unseen', "Error reported correctly" ); |
562 |
ok( !$updated, "Issue not reported as updated when moved from final to too unseen" ); |
563 |
$checkout->discard_changes(); |
564 |
is( $checkout->auto_renew_error, 'too_unseen', "Error updated" ); |
565 |
|
566 |
$renew_error = "auto_renew_final"; |
567 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
568 |
ok( $success, "Issue is renewed when error is 'auto_renew_final'" ); |
569 |
is( $error, 'auto_renew_final', "Error of finality reported when renewed" ); |
570 |
ok( $updated, "Issue reported as updated when renewed" ); |
571 |
$checkout->discard_changes(); |
572 |
is( $checkout->auto_renew_error, 'auto_renew_final', "Error updated" ); |
573 |
|
574 |
$renew_error = "too_many"; |
575 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
576 |
ok( !$success, "Issue is not renewed when error is 'too_many'" ); |
577 |
is( $error, 'too_many', "Error reported correctly" ); |
578 |
ok( !$updated, "Issue not reported as updated when moved from final to too many" ); |
579 |
$checkout->discard_changes(); |
580 |
is( $checkout->auto_renew_error, 'too_many', "Error updated" ); |
581 |
|
549 |
$schema->storage->txn_rollback; |
582 |
$schema->storage->txn_rollback; |
550 |
}; |
583 |
}; |
551 |
- |
|
|