import fetch from 'node-fetch'; import * as dotenv from 'dotenv'; dotenv.config(); const API_URL = process.env.API_URL || 'http://localhost:3000'; interface User { id: string; email: string; name: string; } interface Conversation { id: string; userId: string; } async function e2eTest() { console.log('๐Ÿงช Starting end-to-end tests...'); try { // Health check const healthResponse = await fetch(`${API_URL}/api/health`); if (!healthResponse.ok) { throw new Error('Health check failed'); } console.log('โœ… Health check passed'); // Test user creation const userResponse = await fetch(`${API_URL}/api/users`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email: 'test@example.com', name: 'Test User' }) }); if (!userResponse.ok) { throw new Error('User creation failed'); } const user = await userResponse.json() as User; console.log('โœ… User creation passed'); // Test conversation creation const conversationResponse = await fetch(`${API_URL}/api/conversations`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: user.id }) }); if (!conversationResponse.ok) { throw new Error('Conversation creation failed'); } const conversation = await conversationResponse.json() as Conversation; console.log('โœ… Conversation creation passed'); // Test message creation const messageResponse = await fetch(`${API_URL}/api/messages`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ conversationId: conversation.id, sender: 'user', content: 'Hello, world!' }) }); if (!messageResponse.ok) { throw new Error('Message creation failed'); } console.log('โœ… Message creation passed'); // Test RAG query const ragResponse = await fetch(`${API_URL}/api/rag/query`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: 'What are your office hours?' }) }); if (!ragResponse.ok) { throw new Error('RAG query failed'); } console.log('โœ… RAG query passed'); console.log('โœ… All end-to-end tests passed!'); } catch (error) { console.error('โŒ End-to-end test failed:', error); process.exit(1); } } e2eTest();