|
Lines 412-426
subtest 'automatic_checkin' => sub {
Link Here
|
| 412 |
|
412 |
|
| 413 |
subtest 'attempt_auto_renew' => sub { |
413 |
subtest 'attempt_auto_renew' => sub { |
| 414 |
|
414 |
|
| 415 |
plan tests => 17; |
415 |
plan tests => 33; |
| 416 |
|
416 |
|
| 417 |
$schema->storage->txn_begin; |
417 |
$schema->storage->txn_begin; |
| 418 |
|
418 |
|
| 419 |
my $renew_error = 'auto_renew'; |
419 |
my $renew_error = 'auto_renew'; |
| 420 |
my $module = Test::MockModule->new('C4::Circulation'); |
420 |
my $module = Test::MockModule->new('C4::Circulation'); |
| 421 |
$module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } ); |
421 |
$module->mock( 'CanBookBeRenewed', sub { return ( 1, $renew_error ) } ); |
| 422 |
my $around_now = dt_from_string(); |
422 |
$module->mock( 'AddRenewal', sub { warn "AddRenewal called" } ); |
| 423 |
$module->mock( 'AddRenewal', sub { warn "AddRenewal called" } ); |
|
|
| 424 |
my $checkout = $builder->build_object( |
423 |
my $checkout = $builder->build_object( |
| 425 |
{ |
424 |
{ |
| 426 |
class => 'Koha::Checkouts', |
425 |
class => 'Koha::Checkouts', |
|
Lines 452-457
subtest 'attempt_auto_renew' => sub {
Link Here
|
| 452 |
is( $error, undef, "No error when renewed" ); |
451 |
is( $error, undef, "No error when renewed" ); |
| 453 |
ok( $updated, "Issue reported as updated when renewed" ); |
452 |
ok( $updated, "Issue reported as updated when renewed" ); |
| 454 |
|
453 |
|
|
|
454 |
$module->mock( 'AddRenewal', sub { return; } ); |
| 455 |
|
| 455 |
$renew_error = 'anything_else'; |
456 |
$renew_error = 'anything_else'; |
| 456 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
457 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
| 457 |
ok( !$success, "Success is untrue for any other status" ); |
458 |
ok( !$success, "Success is untrue for any other status" ); |
|
Lines 471-475
subtest 'attempt_auto_renew' => sub {
Link Here
|
| 471 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
472 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew(); |
| 472 |
ok( !$updated, "Issue not reported as updated when status has not changed" ); |
473 |
ok( !$updated, "Issue not reported as updated when status has not changed" ); |
| 473 |
|
474 |
|
|
|
475 |
$renew_error = "auto_unseen_final"; |
| 476 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
| 477 |
ok( $success, "Issue is renewed when error is 'auto_unseen_final'" ); |
| 478 |
is( $error, 'auto_unseen_final', "Error of finality reported when renewed" ); |
| 479 |
ok( $updated, "Issue reported as updated when renewed" ); |
| 480 |
$checkout->discard_changes(); |
| 481 |
is( $checkout->auto_renew_error, 'auto_unseen_final', "Error updated" ); |
| 482 |
|
| 483 |
$renew_error = "too_unseen"; |
| 484 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
| 485 |
ok( !$success, "Issue is not renewed when error is 'too_unseen'" ); |
| 486 |
is( $error, 'too_unseen', "Error reported correctly" ); |
| 487 |
ok( !$updated, "Issue not reported as updated when moved from final to too unseen" ); |
| 488 |
$checkout->discard_changes(); |
| 489 |
is( $checkout->auto_renew_error, 'too_unseen', "Error updated" ); |
| 490 |
|
| 491 |
$renew_error = "auto_renew_final"; |
| 492 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
| 493 |
ok( $success, "Issue is renewed when error is 'auto_renew_final'" ); |
| 494 |
is( $error, 'auto_renew_final', "Error of finality reported when renewed" ); |
| 495 |
ok( $updated, "Issue reported as updated when renewed" ); |
| 496 |
$checkout->discard_changes(); |
| 497 |
is( $checkout->auto_renew_error, 'auto_renew_final', "Error updated" ); |
| 498 |
|
| 499 |
$renew_error = "too_many"; |
| 500 |
( $success, $error, $updated ) = $checkout->attempt_auto_renew( { confirm => 1 } ); |
| 501 |
ok( !$success, "Issue is not renewed when error is 'too_many'" ); |
| 502 |
is( $error, 'too_many', "Error reported correctly" ); |
| 503 |
ok( !$updated, "Issue not reported as updated when moved from final to too many" ); |
| 504 |
$checkout->discard_changes(); |
| 505 |
is( $checkout->auto_renew_error, 'too_many', "Error updated" ); |
| 506 |
|
| 474 |
$schema->storage->txn_rollback; |
507 |
$schema->storage->txn_rollback; |
| 475 |
}; |
508 |
}; |
| 476 |
- |
|
|