← back to Cypress Awards

frontend/src/test.html

42 lines

<!DOCTYPE html>
<html>
<head>
    <title>API Test</title>
</head>
<body>
    <h1>API Connection Test</h1>
    <button id="testBtn">Test API</button>
    <pre id="output"></pre>

    <script>
        const API_BASE_URL = window.location.origin + '/api';
        const output = document.getElementById('output');

        document.getElementById('testBtn').addEventListener('click', async () => {
            output.textContent = 'Testing...\n';

            try {
                // Test 1: Stats
                output.textContent += '\n1. Testing /api/stats...\n';
                const stats = await fetch(`${API_BASE_URL}/stats`);
                output.textContent += `Status: ${stats.status}\n`;
                const statsData = await stats.json();
                output.textContent += `Data: ${JSON.stringify(statsData, null, 2)}\n`;

                // Test 2: Organizations
                output.textContent += '\n2. Testing /api/organizations...\n';
                const orgs = await fetch(`${API_BASE_URL}/organizations?limit=5&offset=0`);
                output.textContent += `Status: ${orgs.status}\n`;
                const orgsData = await orgs.json();
                output.textContent += `Data: ${JSON.stringify(orgsData, null, 2)}\n`;

                output.textContent += '\n✅ ALL TESTS PASSED!';
            } catch (error) {
                output.textContent += `\n❌ ERROR: ${error.message}\n`;
                output.textContent += `Stack: ${error.stack}\n`;
            }
        });
    </script>
</body>
</html>