from fastapi.testclient import TestClient

from grantflow.api.app import app
from grantflow.tests.integration_helpers import wait_for_terminal_status

client = TestClient(app)


def generate_done_job(input_context: dict[str, str]) -> tuple[str, dict]:
    response = client.post(
        "/generate",
        json={
            "donor_id": "usaid",
            "input_context": input_context,
            "llm_mode": False,
            "hitl_enabled": False,
        },
    )
    assert response.status_code == 200
    job_id = response.json()["job_id"]
    status = wait_for_terminal_status(client, job_id)
    assert status["status"] == "done"
    return job_id, status
