63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from v1.auth.schemas import (
|
|
AuthUser,
|
|
SessionCreateRequest,
|
|
SessionRefreshRequest,
|
|
SessionResponse,
|
|
VerificationCreateRequest,
|
|
VerificationVerifyRequest,
|
|
VerificationResendRequest,
|
|
)
|
|
|
|
|
|
def test_signup_requires_valid_email() -> None:
|
|
with pytest.raises(ValidationError):
|
|
VerificationCreateRequest(
|
|
username="demo", email="not-an-email", password="secret123"
|
|
)
|
|
|
|
|
|
def test_signup_requires_username() -> None:
|
|
with pytest.raises(ValidationError):
|
|
VerificationCreateRequest.model_validate(
|
|
{"email": "user@example.com", "password": "secret123"}
|
|
)
|
|
|
|
|
|
def test_signup_verify_requires_six_digit_token() -> None:
|
|
with pytest.raises(ValidationError):
|
|
VerificationVerifyRequest(email="user@example.com", token="abc123")
|
|
|
|
|
|
def test_signup_resend_requires_valid_email() -> None:
|
|
with pytest.raises(ValidationError):
|
|
VerificationResendRequest(email="invalid")
|
|
|
|
|
|
def test_login_requires_valid_email() -> None:
|
|
with pytest.raises(ValidationError):
|
|
SessionCreateRequest(email="invalid", password="secret123")
|
|
|
|
|
|
def test_refresh_requires_token() -> None:
|
|
with pytest.raises(ValidationError):
|
|
SessionRefreshRequest(refresh_token="")
|
|
|
|
|
|
def test_session_response_maps_user() -> None:
|
|
user = AuthUser(id="user-1", email="user@example.com")
|
|
response = SessionResponse(
|
|
access_token="access",
|
|
refresh_token="refresh",
|
|
expires_in=3600,
|
|
token_type="bearer",
|
|
user=user,
|
|
)
|
|
|
|
assert response.user.id == "user-1"
|
|
assert response.user.email == "user@example.com"
|