Spaces:
Paused

File size: 1,590 Bytes
b7980f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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"