File size: 2,850 Bytes
fb14972 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | 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(); |