diff --git a/e2e/docker-compose.test.yml b/e2e/docker-compose.test.yml index f419676..fc456bd 100644 --- a/e2e/docker-compose.test.yml +++ b/e2e/docker-compose.test.yml @@ -1,8 +1,8 @@ services: app: build: - context: ../backend - dockerfile: Dockerfile + context: .. + dockerfile: backend/Dockerfile container_name: ai-synth-test restart: "no" environment: diff --git a/e2e/tests/generation-live.spec.ts b/e2e/tests/generation-live.spec.ts index c3044c7..1308c1a 100644 --- a/e2e/tests/generation-live.spec.ts +++ b/e2e/tests/generation-live.spec.ts @@ -12,9 +12,12 @@ import { test, expect } from '@playwright/test'; import type { Page } from '@playwright/test'; import * as dotenv from 'dotenv'; import * as path from 'path'; +import { fileURLToPath } from 'url'; import { loginAsUser } from '../helpers/auth'; -// Load .env.test from the e2e directory +// Load .env.test from the e2e directory (ESM-compatible __dirname) +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); dotenv.config({ path: path.resolve(__dirname, '..', '.env.test') }); const OPENAI_KEY = process.env.OPENAI_TEST_API_KEY; @@ -120,10 +123,11 @@ test.describe('Live generation with OpenAI', () => { }) => { test.setTimeout(180_000); - // Navigate to app first (required for cookie domain), then login + // Set session cookie, then navigate to a stable page // OpenAI provider is already enabled from the migration seed data - await page.goto('/'); await loginAsUser(page); + await page.goto('/'); + await page.waitForLoadState('networkidle'); // Step 2: Configure settings const settingsResp = await apiCall(page, 'PUT', '/api/v1/settings', { @@ -145,12 +149,19 @@ test.describe('Live generation with OpenAI', () => { }); expect(keyResp.status).toBe(200); - // Step 4: Add a source + // Step 4: Clean up existing sources, then add a fresh one + const existingSources = await apiCall(page, 'GET', '/api/v1/sources'); + if (existingSources.data && Array.isArray(existingSources.data)) { + for (const source of existingSources.data) { + await apiCall(page, 'DELETE', `/api/v1/sources/${source.id}`); + } + } + const sourceResp = await apiCall(page, 'POST', '/api/v1/sources', { title: 'OpenAI Blog', url: 'https://openai.com/blog', }); - expect(sourceResp.status).toBe(200); + expect(sourceResp.status).toBe(201); // Step 5: Trigger generation const genResp = await apiCall(