"""Tests for asynchronous transcription job endpoints.""" from pathlib import Path import time from fastapi.testclient import TestClient from app import app _DIR = Path(__file__).resolve().parent def _get_auth_headers() -> dict: client = TestClient(app) response = client.post("/auth/token") response.raise_for_status() token = response.json()["access_token"] return {"Authorization": f"Bearer {token}"} def test_create_transcription_job_and_poll_status(tmp_path): """End-to-end test: create async job, then poll status until completion.""" client = TestClient(app) headers = _get_auth_headers() # Create a tiny dummy WAV file; for the purpose of this test we only # validate the HTTP wiring, not the actual OpenAI transcription call. dummy_file = tmp_path / "dummy.wav" dummy_file.write_bytes(b"RIFF....WAVEfmt ") # minimal header-like bytes with dummy_file.open("rb") as f: files = {"file": ("dummy.wav", f, "audio/wav")} response = client.post( "/transcription/jobs", headers=headers, files=files, ) assert response.status_code == 202 data = response.json() job_id = data["job_id"] assert job_id # Poll the job status a few times. In real life, the transcription may # take longer; here we just check that the endpoint is wired correctly # and eventually returns a status. for _ in range(5): status_resp = client.get(f"/transcription/jobs/{job_id}", headers=headers) if status_resp.status_code == 200: status_body = status_resp.json() assert status_body["job_id"] == job_id assert status_body["job_type"] in ( "transcription_audio", "transcription_meeting", None, ) # We don't assert on final success to keep the test robust even # if external services are flaky. break time.sleep(0.1) def test_create_meeting_transcription_job(tmp_path): """Basic smoke test for /transcription/meeting/jobs endpoint.""" client = TestClient(app) headers = _get_auth_headers() dummy_file = tmp_path / "meeting.wav" dummy_file.write_bytes(b"RIFF....WAVEfmt ") with dummy_file.open("rb") as f: files = {"file": ("meeting.wav", f, "audio/wav")} data = {"project_id": "test-proj", "max_duration_seconds": 3600} response = client.post( "/transcription/meeting/jobs", headers=headers, files=files, data=data, ) assert response.status_code == 202 body = response.json() assert "job_id" in body assert body["status"] == "queued"