Demon1212122's picture
chore: reapply local updates
fb14972
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();