fix(api): regenerate raw_999_text in /api/acks/{id} detail response (SP3 P3 follow-up)

The P3 subagent shipped a Download button on /acks that fell back to
'no raw text' because the detail endpoint returned raw_json (the parsed
model dump) but never the regenerated X12.

Fix: detail endpoint now re-serializes raw_json via serialize_999 and
returns it as raw_999_text, so the operator can actually download the
999 file. List endpoint unchanged (keeps payload small).
This commit is contained in:
Tyler
2026-06-20 08:06:21 -06:00
parent fb2a98fc7a
commit f3002e4cbe
2 changed files with 46 additions and 0 deletions
+32
View File
@@ -108,3 +108,35 @@ def test_parse_999_rejected_fixture_surfaces_r_code(client: TestClient):
assert body["ack"]["ack_code"] == "R"
assert body["ack"]["rejected_count"] == 1
assert body["ack"]["accepted_count"] == 0
def test_get_ack_detail_regenerates_x12_text(client: TestClient) -> None:
"""SP3 P3 follow-up: GET /api/acks/{id} must include `raw_999_text`
regenerated from raw_json so the operator can actually download the
999 file. The P3 subagent shipped `raw_999_text: None` as a stub."""
text = REJECTED.read_text()
post_resp = client.post(
"/api/parse-999",
files={"file": ("rejected_999.txt", text, "text/plain")},
headers={"Accept": "application/json"},
)
assert post_resp.status_code == 200
ack_id = post_resp.json()["ack"]["id"]
detail_resp = client.get(f"/api/acks/{ack_id}", headers={"Accept": "application/json"})
assert detail_resp.status_code == 200, detail_resp.text
body = detail_resp.json()
# raw_999_text must be present and non-empty X12.
assert "raw_999_text" in body
assert body["raw_999_text"] is not None
assert body["raw_999_text"].startswith("ISA*")
assert "AK1*" in body["raw_999_text"]
assert "AK9*" in body["raw_999_text"]
# IEA segment exists in output; serializer writes `IEA*1*<icn>~`.
assert "IEA*" in body["raw_999_text"]
assert body["raw_999_text"].rstrip().endswith("~")
def test_get_ack_404_for_missing(client: TestClient) -> None:
"""GET /api/acks/{id} returns 404 for a missing id (not 500)."""
resp = client.get("/api/acks/9999", headers={"Accept": "application/json"})
assert resp.status_code == 404