import { test, expect } from '@playwright/test';

const API_URL = process.env.E2E_API_URL || 'http://localhost:3000';

test.describe('API Health & Swagger', () => {
  test('GET /health — проверка доступности API', async ({ request }) => {
    // API may not have /health endpoint yet — check that API responds
    const response = await request.get(`${API_URL}/v1/auth/login`, {
      failOnStatusCode: false,
    });
    // Any response (even 405 Method Not Allowed) means the server is up
    expect(response.status()).toBeLessThan(500);
  });

  test('GET /api/docs — Swagger UI доступен', async ({ request }) => {
    const response = await request.get(`${API_URL}/api/docs`);
    // Swagger returns HTML page
    expect(response.status()).toBeLessThan(400);
  });

  test('GET / — редирект на /api/docs', async ({ request }) => {
    const response = await request.get(`${API_URL}/`, { maxRedirects: 0 });
    // Should redirect
    expect([200, 301, 302, 303, 307, 308]).toContain(response.status());
  });
});
