@ -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 ( 20 1 ) ;
// Step 5: Trigger generation
// Step 5: Trigger generation
const genResp = await apiCall (
const genResp = await apiCall (