| 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 { |
| |
| const healthResponse = await fetch(`${API_URL}/api/health`); |
| if (!healthResponse.ok) { |
| throw new Error('Health check failed'); |
| } |
| console.log('β
Health check passed'); |
|
|
| |
| 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'); |
|
|
| |
| 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'); |
|
|
| |
| 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'); |
|
|
| |
| 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(); |