"""Integration tests for the `/ui` router (spec §PR 2). Covers the full round-trip through `POST /ui/jobs` — the handler parses multipart form data into a `RequestIX` and hands it to `ix.store.jobs_repo.insert_pending`, the same entry point the REST adapter uses. Tests assert the job row exists with the right client/request ids and that custom-use-case forms produce a `use_case_inline` block in the stored request JSON. The DB-touching tests depend on the shared integration conftest which spins up migrations against the configured Postgres; the pure-template tests (`GET /ui` and the fragment renderer) still need a factory but won't actually query — they're cheap. """ from __future__ import annotations import json from collections.abc import Iterator from pathlib import Path from uuid import uuid4 import pytest from fastapi.testclient import TestClient from sqlalchemy import select from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine from ix.adapters.rest.routes import Probes, get_probes, get_session_factory_dep from ix.app import create_app from ix.store.models import IxJob FIXTURE_DIR = Path(__file__).resolve().parents[1] / "fixtures" FIXTURE_PDF = FIXTURE_DIR / "synthetic_giro.pdf" def _factory_for_url(postgres_url: str): # type: ignore[no-untyped-def] def _factory(): # type: ignore[no-untyped-def] eng = create_async_engine(postgres_url, pool_pre_ping=True) return async_sessionmaker(eng, expire_on_commit=False) return _factory @pytest.fixture def app(postgres_url: str) -> Iterator[TestClient]: app_obj = create_app(spawn_worker=False) app_obj.dependency_overrides[get_session_factory_dep] = _factory_for_url( postgres_url ) app_obj.dependency_overrides[get_probes] = lambda: Probes( ollama=lambda: "ok", ocr=lambda: "ok" ) with TestClient(app_obj) as client: yield client class TestIndexPage: def test_index_returns_html(self, app: TestClient) -> None: resp = app.get("/ui") assert resp.status_code == 200 assert "text/html" in resp.headers["content-type"] body = resp.text # Dropdown prefilled with the registered use case. assert "bank_statement_header" in body # Marker for the submission form. assert '