fix(api): include adjustments array in /api/remittances list response (SP3 P2 follow-up)

The P2 subagent shipped a UI chevron+expansion in Remittances.tsx that
read adjustments from the list payload, but iter_remittances() didn't
include the CasAdjustment rows. Result: the expansion was always empty
when a remittance was opened from the list (the detail endpoint worked).

Fix: bulk-fetch all CasAdjustment rows for the remittance_ids in one
query, then attach them as the 'adjustments' array. N+1-free.
This commit is contained in:
Tyler
2026-06-20 07:49:20 -06:00
parent 2a853857b1
commit 7a20f732f2
2 changed files with 62 additions and 0 deletions
+37
View File
@@ -149,6 +149,43 @@ def test_remittances_filters_by_batch_id(seeded_store):
assert resp.json()["items"] == []
# --------------------------------------------------------------------------- #
# /api/remittances list payload includes adjustments array (SP3 P2 follow-up)
# --------------------------------------------------------------------------- #
def test_list_remittances_includes_adjustments_array(client: TestClient) -> None:
"""SP3 P2 follow-up: the list endpoint must include `adjustments` so the
UI's expandable row has data when a remittance is opened from the list
(not just from the detail endpoint)."""
_seed_835_remittance(
pcns=["PCN-LIST-1"],
cas_rows={"PCN-LIST-1": [("CO", "45", "50.00", ""), ("PR", "1", "10.00", "")]},
)
resp = client.get("/api/remittances", headers=JSON)
assert resp.status_code == 200
body = resp.json()
assert len(body["items"]) == 1
item = body["items"][0]
assert "adjustments" in item, item
assert len(item["adjustments"]) == 2
# Verify labels come through (resolved by cas_codes.reason_label).
labels = {a["reason"]: a["label"] for a in item["adjustments"]}
assert "45" in labels and "1" in labels
assert labels["45"] # non-empty
assert labels["1"]
def test_list_remittances_empty_adjustments_is_empty_array(client: TestClient) -> None:
"""A remittance with no CAS rows must still expose `adjustments: []`."""
_seed_835_remittance(pcns=["PCN-LIST-EMPTY"], cas_rows=None)
resp = client.get("/api/remittances", headers=JSON)
assert resp.status_code == 200
body = resp.json()
assert len(body["items"]) == 1
assert body["items"][0]["adjustments"] == []
# --------------------------------------------------------------------------- #
# /api/providers
# --------------------------------------------------------------------------- #