File size: 1,510 Bytes
3998131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
Run: pytest api/test_supabase_auth.py -v
"""
import pytest
from fastapi.testclient import TestClient
from api.main import app

client = TestClient(app)


def test_signup():
    """Test user signup."""
    response = client.post(
        "/api/v1/auth/signup",
        json={
            "email": f"test-{id(object())}@example.com",
            "password": "TestPassword123!",
            "full_name": "Test User",
        },
    )
    # Note: Supabase may require email verification, so this might fail in some configurations
    print(f"Signup response: {response.status_code}")
    if response.status_code == 200:
        assert "access_token" in response.json()


def test_health_check():
    """Test health check endpoint."""
    response = client.get("/health")
    assert response.status_code == 200
    assert response.json()["status"] == "healthy"


def test_root():
    """Test root endpoint."""
    response = client.get("/")
    assert response.status_code == 200
    assert "message" in response.json()


def test_protected_endpoint_without_token():
    """Test that protected endpoint requires token."""
    response = client.get("/api/v1/auth/me")
    assert response.status_code == 403  # Forbidden without token


def test_protected_endpoint_with_invalid_token():
    """Test that invalid token is rejected."""
    response = client.get(
        "/api/v1/auth/me",
        headers={"Authorization": "Bearer invalid.token.here"},
    )
    assert response.status_code == 401  # Unauthorized