|
Lines 18-24
Link Here
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
| 21 |
use Test::More tests => 109; |
21 |
use Test::More tests => 110; |
| 22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
| 23 |
use Test::Mojo; |
23 |
use Test::Mojo; |
| 24 |
use t::lib::Mocks; |
24 |
use t::lib::Mocks; |
|
Lines 527-529
subtest 'add checkout' => sub {
Link Here
|
| 527 |
|
527 |
|
| 528 |
$schema->storage->txn_rollback; |
528 |
$schema->storage->txn_rollback; |
| 529 |
}; |
529 |
}; |
| 530 |
- |
530 |
|
|
|
531 |
subtest 'renew with fine override (x-koha-override: debt_limit)' => sub { |
| 532 |
plan tests => 15; |
| 533 |
|
| 534 |
$schema->storage->txn_begin; |
| 535 |
|
| 536 |
# Create a librarian with circulate permission |
| 537 |
my $librarian = $builder->build_object( |
| 538 |
{ |
| 539 |
class => 'Koha::Patrons', |
| 540 |
value => { flags => 2 } # Superlibrarian |
| 541 |
} |
| 542 |
); |
| 543 |
my $password = 'thePassword123'; |
| 544 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 545 |
my $userid = $librarian->userid; |
| 546 |
|
| 547 |
# Create a regular patron |
| 548 |
my $patron = $builder->build_object( |
| 549 |
{ |
| 550 |
class => 'Koha::Patrons', |
| 551 |
value => { flags => 0 } |
| 552 |
} |
| 553 |
); |
| 554 |
|
| 555 |
# Create a branch and set up userenv |
| 556 |
my $branch = $builder->build( { source => 'Branch' } ); |
| 557 |
t::lib::Mocks::mock_userenv( |
| 558 |
{ branchcode => $branch->{branchcode}, borrowernumber => $librarian->borrowernumber } ); |
| 559 |
|
| 560 |
# Set up circulation rules |
| 561 |
Koha::CirculationRules->set_rules( |
| 562 |
{ |
| 563 |
categorycode => undef, |
| 564 |
itemtype => undef, |
| 565 |
branchcode => undef, |
| 566 |
rules => { |
| 567 |
renewalperiod => 7, |
| 568 |
renewalsallowed => 10, |
| 569 |
issuelength => 5, |
| 570 |
} |
| 571 |
} |
| 572 |
); |
| 573 |
|
| 574 |
my $item = $builder->build_sample_item; |
| 575 |
|
| 576 |
# Check out the item |
| 577 |
my $checkout = AddIssue( $patron, $item->barcode ); |
| 578 |
|
| 579 |
# Set FineNoRenewals to a low amount |
| 580 |
t::lib::Mocks::mock_preference( 'FineNoRenewals', 5 ); |
| 581 |
|
| 582 |
# Add a fine that exceeds the limit |
| 583 |
my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); |
| 584 |
$account->add_debit( |
| 585 |
{ |
| 586 |
amount => 10.00, |
| 587 |
type => 'OVERDUE', |
| 588 |
interface => 'test', |
| 589 |
description => 'Test fine', |
| 590 |
item_id => $item->itemnumber, |
| 591 |
} |
| 592 |
); |
| 593 |
|
| 594 |
my $checkout_id = $checkout->id; |
| 595 |
|
| 596 |
# Test 1: Renewal should be blocked due to excessive fines |
| 597 |
$t->post_ok("//$userid:$password@/api/v1/checkouts/$checkout_id/renewal")->status_is(403) |
| 598 |
->json_like( '/error' => qr/too_much_owing/ ); |
| 599 |
|
| 600 |
# Test 2: Override should fail when AllowFineOverrideRenewing is disabled |
| 601 |
t::lib::Mocks::mock_preference( 'AllowFineOverrideRenewing', 0 ); |
| 602 |
|
| 603 |
$t->post_ok( "//$userid:$password@/api/v1/checkouts/$checkout_id/renewal" => { 'x-koha-override' => 'debt_limit' } ) |
| 604 |
->status_is(403)->json_like( '/error' => qr/too_much_owing/ ); |
| 605 |
|
| 606 |
# Test 3: Override should succeed when AllowFineOverrideRenewing is enabled |
| 607 |
t::lib::Mocks::mock_preference( 'AllowFineOverrideRenewing', 1 ); |
| 608 |
|
| 609 |
$t->post_ok( "//$userid:$password@/api/v1/checkouts/$checkout_id/renewal" => { 'x-koha-override' => 'debt_limit' } ) |
| 610 |
->status_is(201)->json_has('/due_date'); |
| 611 |
|
| 612 |
# Refresh checkout |
| 613 |
$checkout = Koha::Checkouts->find($checkout_id); |
| 614 |
|
| 615 |
# Test 4: Test with /renewals endpoint (alternative endpoint) |
| 616 |
# Add another checkout to test the other endpoint |
| 617 |
my $item2 = $builder->build_sample_item; |
| 618 |
my $checkout2 = AddIssue( $patron, $item2->barcode ); |
| 619 |
my $checkout2_id = $checkout2->id; |
| 620 |
|
| 621 |
# Should be blocked without override |
| 622 |
$t->post_ok("//$userid:$password@/api/v1/checkouts/$checkout2_id/renewals")->status_is(403) |
| 623 |
->json_like( '/error' => qr/too_much_owing/ ); |
| 624 |
|
| 625 |
# Should succeed with override |
| 626 |
$t->post_ok( |
| 627 |
"//$userid:$password@/api/v1/checkouts/$checkout2_id/renewals" => { 'x-koha-override' => 'debt_limit' } ) |
| 628 |
->status_is(201)->json_has('/due_date'); |
| 629 |
|
| 630 |
$schema->storage->txn_rollback; |
| 631 |
}; |