people-reading/backend/tests/test_auth.py
2026-05-11 23:26:11 +08:00

18 lines
668 B
Python

import pytest
from httpx import ASGITransport, AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_anonymous_login_returns_reusable_user_token():
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as client:
first = await client.post("/api/v1/auth/anonymous-login", json={"client_id": "browser-1"})
second = await client.post("/api/v1/auth/anonymous-login", json={"client_id": "browser-1"})
assert first.status_code == 200
assert second.status_code == 200
assert first.json()["user_id"] == second.json()["user_id"]
assert first.json()["access_token"]