Bugzilla – Attachment 188341 Details for
Bug 23415
Notify patron fines when renewing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 23415: Add API tests for fine override on renewal
Bug-23415-Add-API-tests-for-fine-override-on-renew.patch (text/plain), 4.84 KB, created by
Martin Renvoize (ashimema)
on 2025-10-23 11:25:44 UTC
(
hide
)
Description:
Bug 23415: Add API tests for fine override on renewal
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-10-23 11:25:44 UTC
Size:
4.84 KB
patch
obsolete
>From 35db7c78cca1f5ab433ef095eb3cd5c0796b0bba Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >Date: Thu, 23 Oct 2025 12:23:31 +0100 >Subject: [PATCH] Bug 23415: Add API tests for fine override on renewal > >This commit adds comprehensive REST API tests to verify the >x-koha-override: debt_limit functionality for renewals. > >Tests cover: >- Renewal blocked due to excessive fines >- Override fails when AllowFineOverrideRenewing is disabled >- Override succeeds when AllowFineOverrideRenewing is enabled >- Both /renewal and /renewals endpoints > >Test plan: >1. Run: prove t/db_dependent/api/v1/checkouts.t >2. All 110 tests should pass >--- > t/db_dependent/api/v1/checkouts.t | 104 +++++++++++++++++++++++++++++- > 1 file changed, 103 insertions(+), 1 deletion(-) > >diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t >index 7a00bd50ed6..85577c75c33 100755 >--- a/t/db_dependent/api/v1/checkouts.t >+++ b/t/db_dependent/api/v1/checkouts.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 109; >+use Test::More tests => 110; > use Test::MockModule; > use Test::Mojo; > use t::lib::Mocks; >@@ -527,3 +527,105 @@ subtest 'add checkout' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'renew with fine override (x-koha-override: debt_limit)' => sub { >+ plan tests => 15; >+ >+ $schema->storage->txn_begin; >+ >+ # Create a librarian with circulate permission >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2 } # Superlibrarian >+ } >+ ); >+ my $password = 'thePassword123'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ # Create a regular patron >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ # Create a branch and set up userenv >+ my $branch = $builder->build( { source => 'Branch' } ); >+ t::lib::Mocks::mock_userenv( >+ { branchcode => $branch->{branchcode}, borrowernumber => $librarian->borrowernumber } ); >+ >+ # Set up circulation rules >+ Koha::CirculationRules->set_rules( >+ { >+ categorycode => undef, >+ itemtype => undef, >+ branchcode => undef, >+ rules => { >+ renewalperiod => 7, >+ renewalsallowed => 10, >+ issuelength => 5, >+ } >+ } >+ ); >+ >+ my $item = $builder->build_sample_item; >+ >+ # Check out the item >+ my $checkout = AddIssue( $patron, $item->barcode ); >+ >+ # Set FineNoRenewals to a low amount >+ t::lib::Mocks::mock_preference( 'FineNoRenewals', 5 ); >+ >+ # Add a fine that exceeds the limit >+ my $account = Koha::Account->new( { patron_id => $patron->borrowernumber } ); >+ $account->add_debit( >+ { >+ amount => 10.00, >+ type => 'OVERDUE', >+ interface => 'test', >+ description => 'Test fine', >+ item_id => $item->itemnumber, >+ } >+ ); >+ >+ my $checkout_id = $checkout->id; >+ >+ # Test 1: Renewal should be blocked due to excessive fines >+ $t->post_ok("//$userid:$password@/api/v1/checkouts/$checkout_id/renewal")->status_is(403) >+ ->json_like( '/error' => qr/too_much_owing/ ); >+ >+ # Test 2: Override should fail when AllowFineOverrideRenewing is disabled >+ t::lib::Mocks::mock_preference( 'AllowFineOverrideRenewing', 0 ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/checkouts/$checkout_id/renewal" => { 'x-koha-override' => 'debt_limit' } ) >+ ->status_is(403)->json_like( '/error' => qr/too_much_owing/ ); >+ >+ # Test 3: Override should succeed when AllowFineOverrideRenewing is enabled >+ t::lib::Mocks::mock_preference( 'AllowFineOverrideRenewing', 1 ); >+ >+ $t->post_ok( "//$userid:$password@/api/v1/checkouts/$checkout_id/renewal" => { 'x-koha-override' => 'debt_limit' } ) >+ ->status_is(201)->json_has('/due_date'); >+ >+ # Refresh checkout >+ $checkout = Koha::Checkouts->find($checkout_id); >+ >+ # Test 4: Test with /renewals endpoint (alternative endpoint) >+ # Add another checkout to test the other endpoint >+ my $item2 = $builder->build_sample_item; >+ my $checkout2 = AddIssue( $patron, $item2->barcode ); >+ my $checkout2_id = $checkout2->id; >+ >+ # Should be blocked without override >+ $t->post_ok("//$userid:$password@/api/v1/checkouts/$checkout2_id/renewals")->status_is(403) >+ ->json_like( '/error' => qr/too_much_owing/ ); >+ >+ # Should succeed with override >+ $t->post_ok( >+ "//$userid:$password@/api/v1/checkouts/$checkout2_id/renewals" => { 'x-koha-override' => 'debt_limit' } ) >+ ->status_is(201)->json_has('/due_date'); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.51.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 23415
:
92039
|
92541
|
98442
|
98634
|
98996
|
98997
|
105893
|
105894
|
108392
|
109871
|
109872
|
109876
|
109880
|
116919
|
116920
|
116921
|
116922
|
118175
|
118176
|
118177
|
118178
|
118183
|
119300
|
119301
|
119302
|
119303
|
121472
|
139670
|
139671
|
139672
|
139673
|
139674
|
146415
|
148198
|
148199
|
148200
|
148201
|
148202
|
152776
|
152777
|
152778
|
152779
|
152780
|
152781
|
154595
|
154596
|
154597
|
154598
|
154599
|
154600
|
158302
|
158303
|
158304
|
158305
|
158306
|
158307
|
161964
|
161965
|
161966
|
161967
|
161968
|
161969
|
162171
|
162172
|
162173
|
162174
|
162175
|
162176
|
162177
|
162178
|
162179
|
162180
|
171620
|
171621
|
171622
|
171623
|
171983
|
171984
|
171985
|
171986
|
172906
|
172907
|
172908
|
172909
|
172910
|
185270
|
185271
|
185272
|
185273
|
185274
|
185275
|
186014
|
188331
|
188332
|
188333
|
188334
|
188335
|
188336
|
188337
|
188338
|
188339
|
188340
| 188341 |
188342