Bug 39869

Summary: Club holds API missing tests
Product: Koha Reporter: Tomás Cohen Arazi (tcohen) <tomascohen>
Component: Test SuiteAssignee: Tomás Cohen Arazi (tcohen) <tomascohen>
Status: Pushed to main --- QA Contact: Katrin Fischer <katrin.fischer>
Severity: normal    
Priority: P5 - low CC: tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38944
GIT URL: Change sponsored?: ---
Patch complexity: Small patch Documentation contact:
Documentation submission: Text to go in the release notes:
Version(s) released in:
25.05.00
Circulation function:
Bug Depends on: 25787    
Bug Blocks:    
Attachments: Bug 39869: Add more tests for the club holds endpoint

Description Tomás Cohen Arazi (tcohen) 2025-05-09 13:55:48 UTC
The introduction of `Test::NoWarnings` (bug 38944) allowed us to detect these tests do not cover all the behavior: when the database makes `Can*BeReserved` not return `status => OK` the tests pass (because the endpoint is designed to place the hold regardless, but a warning is printed in the logs.

This behavior is not tested.

The tests should:

* Cover the item-level holds case
* Not depend on existing data/circulation rules on the DB
* Tests this `warn` behavior correctly
Comment 1 Tomás Cohen Arazi (tcohen) 2025-05-09 14:00:32 UTC
Created attachment 182177 [details] [review]
Bug 39869: Add more tests for the club holds endpoint

This patch does:

* Mock `CanItemBeReserved` and `CanBookBeReserved` to better control the
  test scenario and make it agnostic from existing data.
* Adds tests for the item-level group holds use case
* Adds tests for the warnings printed when placing the hold should not
  be possible

To test:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ prove t/db_dependent/api/v1/clubs_holds.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>