import pytest
from httpx import ASGITransport, AsyncClient

from app.main import app


@pytest.fixture
def anyio_backend():
    return "asyncio"


@pytest.mark.anyio
async def test_home_page():
    async with AsyncClient(
        transport=ASGITransport(app=app), base_url="http://testserver"
    ) as client:
        response = await client.get("/")

    assert response.status_code == 200
    assert "See how fast that was?" in response.text


@pytest.mark.anyio
async def test_status_api():
    async with AsyncClient(
        transport=ASGITransport(app=app), base_url="http://testserver"
    ) as client:
        response = await client.get("/api/status")

    assert response.status_code == 200
    assert response.json()["app"] == "FastApp"


@pytest.mark.anyio
async def test_hello_partial():
    async with AsyncClient(
        transport=ASGITransport(app=app), base_url="http://testserver"
    ) as client:
        response = await client.get("/partials/hello")

    assert response.status_code == 200
    assert response.text == "<p>FastAPI answered. Tell your agent what comes next.</p>"
