"""Tests for authentication endpoints.""" import pytest from faker import Faker fake = Faker() @pytest.mark.unit def test_health_check(client): """Test health check endpoint.""" response = client.get("/health") assert response.status_code == 200 data = response.json() assert data["status"] == "healthy" @pytest.mark.unit def test_register_missing_fields(client): """Test registration with missing required fields.""" response = client.post("/api/v1/auth/register", json={}) assert response.status_code == 422 # Validation error @pytest.mark.unit def test_register_weak_password(client, override_get_session): """Test registration with weak password.""" response = client.post("/api/v1/auth/register", json={ "email": fake.email(), "password": "weak", # Too short "company_name": "Test Company" }) assert response.status_code == 400 assert "at least 8 characters" in response.json()["detail"].lower() @pytest.mark.integration async def test_register_success(client, override_get_session): """Test successful registration.""" email = fake.email() response = client.post("/api/v1/auth/register", json={ "email": email, "password": "SecurePass123!", "company_name": "Test Company", "full_name": "Test User" }) assert response.status_code == 200 data = response.json() assert "access_token" in data assert data["user"]["email"] == email assert "tenant_id" in data["user"] @pytest.mark.unit def test_login_invalid_credentials(client, override_get_session): """Test login with invalid credentials.""" response = client.post("/api/v1/auth/login", json={ "email": "nonexistent@example.com", "password": "WrongPassword123" }) assert response.status_code == 401 assert "invalid credentials" in response.json()["detail"].lower()