"""Tests that /api/parse-837 includes the persisted batch_id in its
JSON response, so the frontend can correlate its in-memory batch with
the server's row (and later call /api/batches/{id}/export-837).

The 409 (duplicate) path has always included batch_id; the 200 path
did not. This brings the 200 path in line so the frontend doesn't have
to query listBatches after every parse just to learn the server's id.
"""
import io
from pathlib import Path

from fastapi.testclient import TestClient

from cyclone.api import app


def test_parse_837_happy_path_includes_batch_id_in_response():
    with TestClient(app) as client:
        fixture = Path("tests/fixtures/co_medicaid_837p.txt").read_text()
        r = client.post(
            "/api/parse-837",
            files={"file": ("claim.txt", io.BytesIO(fixture.encode()), "text/plain")},
            headers={"Accept": "application/json"},
        )
    assert r.status_code == 200, r.text
    body = r.json()
    assert "batch_id" in body, "parse-837 response must include batch_id so the frontend can call /api/batches/{id}/export-837"
    # Sanity: the batch_id should be a non-empty string (UUID-shaped).
    assert isinstance(body["batch_id"], str) and body["batch_id"]
