Monorepo for Aesthetic.Computer
aesthetic.computer
1// Test creating a mood via the API
2// This will test if new moods sync to ATProto
3
4import { readFileSync } from 'fs';
5
6async function testMoodCreation() {
7 console.log('🧪 Testing mood creation and ATProto sync...\n');
8
9 // You'll need a valid auth token to test this
10 // For now, let's just trace through what should happen
11
12 console.log('📋 Flow when creating a new mood:');
13 console.log('1. POST /api/mood with { mood: "test mood" }');
14 console.log('2. Function authorizes user via JWT');
15 console.log('3. Inserts mood into MongoDB moods collection');
16 console.log('4. Calls createMoodOnAtproto() which:');
17 console.log(' - Looks up user ATProto credentials (did + password)');
18 console.log(' - Logs into ATProto PDS');
19 console.log(' - Creates record in computer.aesthetic.mood collection');
20 console.log(' - Updates MongoDB with the rkey');
21 console.log('5. Sends Firebase notification\n');
22
23 console.log('⚠️ Potential issues:');
24 console.log('1. User might not have ATProto credentials in MongoDB users collection');
25 console.log('2. ATProto password might be invalid/expired');
26 console.log('3. PDS might be unreachable');
27 console.log('4. Error handling swallows ATProto errors (mood still saved)\n');
28
29 // Let's check if we can see the mood function code for debugging
30 const moodFunctionPath = './system/netlify/functions/mood.mjs';
31 console.log('📄 Checking mood function error handling...\n');
32
33 const code = readFileSync(moodFunctionPath, 'utf-8');
34
35 // Find the atproto error handling
36 const errorHandlingMatch = code.match(/catch \(atprotoError\)[^}]+}/);
37 if (errorHandlingMatch) {
38 console.log('Current ATProto error handling:');
39 console.log(errorHandlingMatch[0]);
40 console.log('\n');
41 }
42
43 console.log('💡 Recommendation:');
44 console.log('Check Netlify function logs for these messages:');
45 console.log(' - "🔄 Syncing mood to ATProto..."');
46 console.log(' - "✅ Mood synced to ATProto with rkey: XXX"');
47 console.log(' - "⚠️ Failed to sync mood to ATProto: [error]"');
48 console.log('\nIf seeing failures, check:');
49 console.log(' - MongoDB users collection for atproto.did and atproto.password');
50 console.log(' - PDS_URL environment variable');
51 console.log(' - PDS service status\n');
52}
53
54testMoodCreation();