Monorepo for Aesthetic.Computer aesthetic.computer
at main 67 lines 2.4 kB view raw
1// Test script to check the mood API endpoint 2// Run with: node test-mood-api.mjs 3 4async function testMoodAPI() { 5 const apiUrl = 'https://aesthetic.computer'; 6 7 console.log('🔍 Testing mood API endpoint...\n'); 8 console.log(`Fetching: ${apiUrl}/api/mood/all\n`); 9 10 try { 11 const response = await fetch(`${apiUrl}/api/mood/all`); 12 13 console.log('Status:', response.status); 14 console.log('Status Text:', response.statusText); 15 console.log('Headers:', Object.fromEntries(response.headers.entries())); 16 console.log('\n'); 17 18 if (!response.ok) { 19 console.error('❌ Response not OK'); 20 const text = await response.text(); 21 console.error('Response body:', text); 22 return; 23 } 24 25 const data = await response.json(); 26 console.log('✅ Successfully fetched data\n'); 27 console.log('Response type:', Array.isArray(data) ? 'Array' : typeof data); 28 29 if (Array.isArray(data)) { 30 console.log(`📊 Direct array with ${data.length} moods`); 31 console.log('\nFirst 3 moods:'); 32 data.slice(0, 3).forEach((mood, i) => { 33 console.log(`\n${i + 1}.`, JSON.stringify(mood, null, 2)); 34 }); 35 } else if (data && data.moods && Array.isArray(data.moods)) { 36 console.log(`📊 Object with moods property containing ${data.moods.length} moods`); 37 console.log('\nFirst 3 moods:'); 38 data.moods.slice(0, 3).forEach((mood, i) => { 39 console.log(`\n${i + 1}.`, JSON.stringify(mood, null, 2)); 40 }); 41 } else { 42 console.log('⚠️ Unexpected data structure:'); 43 console.log(JSON.stringify(data, null, 2)); 44 } 45 46 // Test with a specific handle 47 console.log('\n\n🔍 Testing with specific handle (@digitpain)...\n'); 48 const handleResponse = await fetch(`${apiUrl}/api/mood/all?for=@digitpain`); 49 const handleData = await handleResponse.json(); 50 51 if (handleData && handleData.moods) { 52 console.log(`📊 Found ${handleData.moods.length} moods for @digitpain`); 53 if (handleData.moods.length > 0) { 54 console.log('\nLatest mood:'); 55 console.log(JSON.stringify(handleData.moods[0], null, 2)); 56 } 57 } else { 58 console.log('Response:', JSON.stringify(handleData, null, 2)); 59 } 60 61 } catch (error) { 62 console.error('❌ Error:', error.message); 63 console.error(error); 64 } 65} 66 67testMoodAPI();