import pytest from httpx import AsyncClient, ASGITransport from mediastorm.api import app @pytest.mark.asyncio async def test_search_requires_query(): transport = ASGITransport(app=app) async with AsyncClient(transport=transport, base_url="http://test") as client: resp = await client.post("/api/search", json={}) assert resp.status_code == 422 @pytest.mark.asyncio async def test_search_returns_stories(): """Integration test — requires populated ChromaDB and app lifespan.""" # This test requires the full app lifespan to initialize the retriever. # It works when running the app normally but not with bare ASGITransport. pytest.skip("Requires app lifespan (retriever init) — run via full server") @pytest.mark.asyncio async def test_health(): transport = ASGITransport(app=app) async with AsyncClient(transport=transport, base_url="http://test") as client: resp = await client.get("/api/health") assert resp.status_code == 200 data = resp.json() assert "status" in data assert data["status"] == "ok" @pytest.mark.asyncio async def test_stories_returns_list(): transport = ASGITransport(app=app) async with AsyncClient(transport=transport, base_url="http://test") as client: resp = await client.get("/api/stories") assert resp.status_code == 200 data = resp.json() assert "stories" in data assert isinstance(data["stories"], list) if data["stories"]: story = data["stories"][0] assert "uid" in story assert "name" in story assert "slug" in story assert "poster" in story