/**
* Simple test script for the Harmony 2.0 Master Agent API
* Run: node test-api.js
*/
const API_URL = process.env.API_URL || 'http://localhost:3000';
async function testAPI() {
console.log('š§Ŗ Testing Harmony 2.0 Master Agent API\n');
// Test 1: Health Check
console.log('1ļøā£ Testing Health Check...');
try {
const healthRes = await fetch(`${API_URL}/health`);
const health = await healthRes.json();
console.log('ā
Health Check:', health);
} catch (error) {
console.error('ā Health Check failed:', error.message);
return;
}
// Test 2: Chat
console.log('\n2ļøā£ Testing Chat...');
try {
const chatRes = await fetch(`${API_URL}/api/chat`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
message: 'What is Harmony 2.0?',
}),
});
const chat = await chatRes.json();
console.log('ā
Chat Response:', chat.response.substring(0, 200) + '...');
} catch (error) {
console.error('ā Chat failed:', error.message);
}
// Test 3: Analyze Code
console.log('\n3ļøā£ Testing Code Analysis...');
try {
const analyzeRes = await fetch(`${API_URL}/api/analyze`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
code: 'function hello() { return "world"; }',
language: 'javascript',
}),
});
const analyze = await analyzeRes.json();
console.log('ā
Analysis Response:', analyze.response.substring(0, 200) + '...');
} catch (error) {
console.error('ā Analysis failed:', error.message);
}
// Test 4: Generate Code
console.log('\n4ļøā£ Testing Code Generation...');
try {
const generateRes = await fetch(`${API_URL}/api/generate`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
description: 'Create a simple React button component',
componentType: 'component',
}),
});
const generate = await generateRes.json();
console.log('ā
Generation Response:', generate.response.substring(0, 200) + '...');
} catch (error) {
console.error('ā Generation failed:', error.message);
}
// Test 5: Get Guidance
console.log('\n5ļøā£ Testing Guidance...');
try {
const guidanceRes = await fetch(`${API_URL}/api/guidance`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
topic: 'project setup',
}),
});
const guidance = await guidanceRes.json();
console.log('ā
Guidance Response:', guidance.response.substring(0, 200) + '...');
} catch (error) {
console.error('ā Guidance failed:', error.message);
}
console.log('\n⨠Testing complete!');
}
// Run tests
testAPI().catch(console.error);