File size: 2,085 Bytes
3e6248e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
55
56
57
58
59
60
61
62
"""
E2E Tests for Credits Endpoints

Tests credit balance and history with real server.
Note: Since we can't mock Google OAuth in a running server,
we test that endpoints properly require authentication.
"""
import pytest


class TestCreditsE2E:
    """Test credits endpoints with real server."""
    
    def test_credits_balance_requires_auth(self, api_client):
        """Credits balance requires authentication."""
        response = api_client.get("/credits/balance")
        
        assert response.status_code == 401
    
    def test_credits_history_requires_auth(self, api_client):
        """Credits history requires authentication."""
        response = api_client.get("/credits/history")
        
        assert response.status_code == 401


class TestProtectedEndpointsE2E:
    """Test that protected endpoints require authentication."""
    
    @pytest.mark.parametrize("endpoint,method", [
        ("/gemini/generate-text", "post"),
        ("/gemini/generate-video", "post"),
        ("/gemini/edit-image", "post"),
        ("/gemini/generate-animation-prompt", "post"),
        ("/gemini/analyze-image", "post"),
        ("/payments/create-order", "post"),
        ("/payments/history", "get"),
        ("/contact", "post"),
    ])
    def test_protected_endpoint_requires_auth(self, api_client, endpoint, method):
        """Protected endpoints return 401 without auth."""
        if method == "post":
            response = api_client.post(endpoint, json={})
        else:
            response = api_client.get(endpoint)
        
        # Should be 401 (unauthorized) - might get 422 if validation runs first
        assert response.status_code in [401, 403, 422]


class TestPaymentsE2E:
    """Test payments endpoints with real server."""
    
    def test_packages_public(self, api_client):
        """Packages endpoint is public."""
        response = api_client.get("/payments/packages")
        
        assert response.status_code == 200
        data = response.json()
        # Should return list of packages
        assert isinstance(data, (list, dict))