from __future__ import annotations

import httpx
import pytest
from fastapi import FastAPI

from codeflash_api._app import create_app


@pytest.fixture(name="app")
def _app() -> FastAPI:
    return create_app()


@pytest.fixture(name="client")
async def _client(app: FastAPI) -> httpx.AsyncClient:
    transport = httpx.ASGITransport(app=app)
    async with httpx.AsyncClient(
        transport=transport, base_url="http://test"
    ) as c:
        yield c


class TestHealthcheck:
    """Tests for GET /healthcheck."""

    async def test_returns_ok(self, client: httpx.AsyncClient) -> None:
        """
        Healthcheck returns 200 with status ok.
        """
        resp = await client.get("/healthcheck")

        assert 200 == resp.status_code
        assert {"status": "ok"} == resp.json()


class TestRouting:
    """Tests for route resolution."""

    async def test_unknown_route_returns_404(
        self, client: httpx.AsyncClient
    ) -> None:
        """
        Unknown routes return 404, not 500.
        """
        resp = await client.get("/nonexistent")

        assert 404 == resp.status_code
