87 lines
2.2 KiB
JavaScript
87 lines
2.2 KiB
JavaScript
/**
|
|
* 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...'); |