import pytest from httpx import AsyncClient @pytest.mark.asyncio async def test_forgot_password_user_exists(client: AsyncClient): """Test forgot password with a valid user.""" # Using 'customer@a.com' from conftest.py / existing seeds if they are there # But since tests use their own db, I'll rely on the conftest setup. response = await client.post( "/api/v1/auth/forgot-password", json={"email": "customer@a.com"} ) # If customer@a.com exists in tests, it should be 200/201 (actually 200 in code) assert response.status_code == 200 data = response.json() assert "reset_token" in data assert "simulated" in data["message"] @pytest.mark.asyncio async def test_forgot_password_user_not_exists(client: AsyncClient): """Test forgot password with a non-existent user.""" response = await client.post( "/api/v1/auth/forgot-password", json={"email": "nonexistent@example.com"} ) # Should be 404 because of my change assert response.status_code == 404 assert response.json()["detail"] == "No account found with this email address." @pytest.mark.asyncio async def test_reset_password_invalid_token(client: AsyncClient): """Test reset password with an invalid token.""" response = await client.post( "/api/v1/auth/reset-password", json={"token": "invalid-token", "new_password": "NewPassword123!"} ) # Should be 400 because of my change (JWTError caught) assert response.status_code == 400 assert response.json()["detail"] == "Invalid or expired reset token"