/** * Test script for bot actions * Usage: node test-bot-action.js * * Examples: * node test-bot-action.js ABC123 '{"action":"draw"}' * node test-bot-action.js ABC123 '{"action":"play","card":"4R"}' * node test-bot-action.js ABC123 '{"action":"play","card":"W","color":"R"}' * node test-bot-action.js ABC123 '{"action":"uno"}' */ const http = require('http'); const roomCode = process.argv[2]; const actionJson = process.argv[3]; if (!roomCode || !actionJson) { console.error('āŒ Usage: node test-bot-action.js '); console.error('Example: node test-bot-action.js ABC123 \'{"action":"draw"}\''); process.exit(1); } let action; try { action = JSON.parse(actionJson); } catch (e) { console.error('āŒ Invalid JSON:', e.message); process.exit(1); } console.log(`šŸ¤– Sending bot action to room ${roomCode}:`); console.log(JSON.stringify(action, null, 2)); const postData = JSON.stringify(action); const options = { hostname: 'localhost', port: 5000, path: `/api/game/${roomCode}/action`, method: 'POST', headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(postData) } }; const req = http.request(options, (res) => { let data = ''; res.on('data', (chunk) => { data += chunk; }); res.on('end', () => { console.log(`\nšŸ“” Response (${res.statusCode}):`); try { const response = JSON.parse(data); console.log(JSON.stringify(response, null, 2)); if (response.success) { console.log('āœ… Action sent successfully!'); } else { console.log('āŒ Action failed'); } } catch (e) { console.log(data); } }); }); req.on('error', (e) => { console.error('āŒ Request failed:', e.message); console.error('Make sure the server is running on port 5000'); }); req.write(postData); req.end();