Inventory HTTP API QA
Manual source API checks for Inventory Unit 5.
Use a test tenant and two facilities. Do not use real patient data in stock references.
Run migrations through 20261011000005_add_inventory_operation_results.rb.
Grant View and the required stock action through Shell. Assign the user to facility A.
Use authenticated JSON requests at /api/inventory/facilities/:facility_id.
The Hospital inventory screen is not connected by this unit.
- Create an item and store/OT locations. Read them with search and pagination.
- Create and update with a code longer than 120 characters, a name longer than 240, or an item base unit longer than 40. Expect HTTP 422 and
VALIDATION_FAILED. No operation, saved value, or version can change. Values at these limits remain valid. - Update configuration with its current version. Retry the old version with a new key; expect
VERSION_CONFLICT. - Publish an input-unit conversion. Read its immutable version and decimal-string factor.
- Receive stock through
POST operationswithkind: receipt. Check exact decimal strings in the result and balances. - Repeat the same key and payload. Expect the same operation with
replayed: trueand no second movement. - Receive more stock, then retry the first receipt. Its
effectscontain the original post-command snapshot, not current stock. - Change a payload but keep its key. Expect
OPERATION_KEY_REUSED. Use a new key for an existing source row; expectDUPLICATE_SOURCE. - Reserve explicit buckets, issue to the OT, consume part, and return unused custody. Compare physical stock, holds, and custody.
- Read reservations, their paginated allocations, and custody allocations. Filter by item, location, and balance identity.
- Filter operation history by key, item, balance, kind, and explicit-offset date range. Unsupported filters return 422, not broad results.
- Read an unresolved lot's
lot_versionfrom balances. Use that string asexpected_versionto validate it with approved expiry evidence. Read its incremented current version, revision, and original operation history. Quantities do not change. - Correct the validation with a fresh lot version, then replay the original validation. Its evidence preserves the original version; balance reads expose the current version. An untracked balance returns
lot_version: null. - Test unresolved, expired, and eligible balance filters. Expired stock has zero allocatable quantity.
- Pass a facility B ID with an invalid quantity. Expect
RESOURCE_NOT_FOUNDbefore quantity details. - Remove View, then remove assignment. Check direct read/write routes deny access. Do not rely on hidden navigation.
- Try a patient field or a service actor in the request body. Expect validation failure and no operation.
- Simulate connection loss. Preserve the key after an unknown outcome; use operation lookup or retry before any new command.
- Confirm normal success envelopes include
dataand pagination metadata. Failures include a canonical error code and command outcome where known.
Automated request tests cover these source routes under tenant and non-bypass RLS contexts. Operator QA, staging deployment, and Hospital U10 integration remain separate acceptance gates.