← back to Melanie Project
test.js
63 lines
const https = require('https');
const fs = require('fs');
// Create a simple 1x1 red pixel PNG image
const testImageBase64 = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8DwHwAFBQIAX8jx0gAAAABJRU5ErkJggg==';
const testImageDataUrl = `data:image/png;base64,${testImageBase64}`;
const postData = JSON.stringify({
photos: [testImageDataUrl]
});
const options = {
hostname: 'localhost',
port: 9876,
path: '/api/hairstyles',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
},
rejectUnauthorized: false
};
console.log('🧪 Testing Melanie API...');
console.log('📸 Sending test image to API...');
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('\n✅ Response received!');
console.log('Status:', res.statusCode);
console.log('\n📋 Response:');
try {
const parsed = JSON.parse(data);
console.log(JSON.stringify(parsed, null, 2));
if (parsed.hairstyles && parsed.hairstyles.length > 0) {
console.log('\n✨ SUCCESS! Got hairstyle recommendation:');
console.log('Celebrity:', parsed.hairstyles[0].celebrityName);
console.log('Style:', parsed.hairstyles[0].styleName);
console.log('Instructions:', parsed.hairstyles[0].stylingInstructions);
} else {
console.log('\n❌ FAILED: No hairstyles returned');
}
} catch (e) {
console.log('Raw response:', data);
console.log('\n❌ FAILED: Could not parse JSON');
}
});
});
req.on('error', (error) => {
console.error('❌ Request failed:', error);
});
req.write(postData);
req.end();