fix: UAT test — ESM compat, correct status codes, idempotent source setup

- Use import.meta.url for ESM-compatible __dirname
- Source creation expects 201, not 200
- Clean up existing sources before adding to avoid unique constraint violation
- Fix E2E docker-compose build context to project root

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
master
oabrivard 3 months ago
parent fb604a408b
commit 69e5f2257a

@ -1,8 +1,8 @@
services: services:
app: app:
build: build:
context: ../backend context: ..
dockerfile: Dockerfile dockerfile: backend/Dockerfile
container_name: ai-synth-test container_name: ai-synth-test
restart: "no" restart: "no"
environment: environment:

@ -12,9 +12,12 @@ import { test, expect } from '@playwright/test';
import type { Page } from '@playwright/test'; import type { Page } from '@playwright/test';
import * as dotenv from 'dotenv'; import * as dotenv from 'dotenv';
import * as path from 'path'; import * as path from 'path';
import { fileURLToPath } from 'url';
import { loginAsUser } from '../helpers/auth'; 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') }); dotenv.config({ path: path.resolve(__dirname, '..', '.env.test') });
const OPENAI_KEY = process.env.OPENAI_TEST_API_KEY; const OPENAI_KEY = process.env.OPENAI_TEST_API_KEY;
@ -120,10 +123,11 @@ test.describe('Live generation with OpenAI', () => {
}) => { }) => {
test.setTimeout(180_000); 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 // OpenAI provider is already enabled from the migration seed data
await page.goto('/');
await loginAsUser(page); await loginAsUser(page);
await page.goto('/');
await page.waitForLoadState('networkidle');
// Step 2: Configure settings // Step 2: Configure settings
const settingsResp = await apiCall(page, 'PUT', '/api/v1/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); 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', { const sourceResp = await apiCall(page, 'POST', '/api/v1/sources', {
title: 'OpenAI Blog', title: 'OpenAI Blog',
url: 'https://openai.com/blog', url: 'https://openai.com/blog',
}); });
expect(sourceResp.status).toBe(200); expect(sourceResp.status).toBe(201);
// Step 5: Trigger generation // Step 5: Trigger generation
const genResp = await apiCall( const genResp = await apiCall(

Loading…
Cancel
Save