import pytest from httpx import AsyncClient @pytest.mark.asyncio async def test_auth_login_customer(client: AsyncClient): """Test standard customer login.""" response = await client.post( "/api/v1/auth/login", data={"username": "customer@a.com", "password": "password123"} ) assert response.status_code == 200 assert "access_token" in response.json() @pytest.mark.asyncio async def test_auth_login_staff_with_portal(client: AsyncClient): """Test staff login specifically with the X-Nexus-Portal header.""" response = await client.post( "/api/v1/auth/login", data={"username": "admin@a.com", "password": "password123"}, headers={"X-Nexus-Portal": "internal"} ) assert response.status_code == 200 assert "access_token" in response.json() @pytest.mark.asyncio async def test_ticket_lifecycle(client: AsyncClient, token_a: str): """Test creating and listing a ticket in Workspace A.""" headers = {"Authorization": f"Bearer {token_a}"} # 1. Create payload = { "title": "Automated Test Ticket", "description": "Functional Test", "priority": "P2", "category": "Setup" } response = await client.post("/api/v1/tickets/", json=payload, headers=headers) assert response.status_code == 201 ticket_id = response.json()["id"] # 2. List list_response = await client.get("/api/v1/tickets/", headers=headers) assert list_response.status_code == 200 assert any(t["id"] == ticket_id for t in list_response.json()) @pytest.mark.asyncio async def test_dashboard_stats_isolation_default(client: AsyncClient, admin_token_a: str): """Test that dashboard stats are restricted to the admin's workspace.""" headers = { "Authorization": f"Bearer {admin_token_a}", "X-Nexus-Portal": "internal" } response = await client.get("/api/v1/dashboard/stats", headers=headers) assert response.status_code == 200 data = response.json() assert "total_tickets" in data # Verifies that it didn't crash or return global leak.