/** * Quick test script for notification system * Run with: node test-notification.js */ const io = require('socket.io-client'); // Test JWT token (you'll need to replace with a real one) const TEST_TOKEN = 'your-jwt-token-here'; console.log('šŸ”” Testing Notification System...\n'); // Connect to Socket.io server const socket = io('http://localhost:3000', { auth: { token: TEST_TOKEN }, transports: ['websocket', 'polling'] }); socket.on('connect', () => { console.log('āœ… Connected to Socket.io server'); console.log('Socket ID:', socket.id); // Test marking notification as read setTimeout(() => { console.log('\nTesting notification operations...'); socket.emit('notification:markRead', 'test-notification-id'); }, 1000); // Test updating preferences setTimeout(() => { console.log('Updating preferences...'); socket.emit('notification:updatePreferences', { email: { enabled: true, frequency: 'instant' }, realtime: { enabled: true, sound: true } }); }, 2000); // Disconnect after tests setTimeout(() => { console.log('\nDisconnecting...'); socket.disconnect(); process.exit(0); }, 5000); }); socket.on('disconnect', (reason) => { console.log('āŒ Disconnected:', reason); }); socket.on('connect_error', (error) => { console.error('āŒ Connection error:', error.message); process.exit(1); }); socket.on('notification:new', (notification) => { console.log('\nšŸ“¬ New notification received:'); console.log(' Title:', notification.title); console.log(' Message:', notification.message); console.log(' Priority:', notification.priority); console.log(' Type:', notification.type); }); socket.on('notification:read', (notificationId) => { console.log('āœ… Notification marked as read:', notificationId); }); socket.on('notifications:allRead', () => { console.log('āœ… All notifications marked as read'); }); socket.on('notifications:pending', (notifications) => { console.log(`šŸ“„ Received ${notifications.length} pending notifications`); }); socket.on('preferences:updated', (preferences) => { console.log('āœ… Preferences updated successfully'); }); console.log('Attempting to connect to Socket.io server...');