File size: 716 Bytes
2756f0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Shared test helpers built only on public endpoints."""

import uuid

import httpx

PASSWORD = "correct-horse-9"


def bearer(token: str) -> dict[str, str]:
    return {"Authorization": f"Bearer {token}"}


async def register(client: httpx.AsyncClient, *, role: str = "player", email: str | None = None) -> dict:
    """Creates an account; returns {"user", "tokens", "headers"}."""
    email = email or f"{role}-{uuid.uuid4().hex[:10]}@example.com"
    response = await client.post("/v1/auth/register", json={"email": email, "password": PASSWORD, "role": role})
    assert response.status_code == 201, response.text
    body = response.json()
    return {**body, "headers": bearer(body["tokens"]["access_token"])}