- Server is running on port 5001
- Client is running on port 3000
- MongoDB is connected
- You have a registered user account
- There's at least one event with registrations
Using Postman or a test script, create a workshop that starts soon:
POST http://localhost:5001/api/workshops
Authorization: Bearer <professor_token>
{
"name": "Test Chat Workshop",
"location": "GUC Cairo",
"startAt": "2025-12-12T14:00:00Z", // Set to current time + 2 minutes
"endAt": "2025-12-12T16:00:00Z",
"startTime": "14:00",
"endTime": "16:00",
"shortDescription": "Testing chat feature",
"fullAgenda": "Test workshop for chat",
"faculty": "Engineering",
"professors": ["Test Professor"],
"requiredBudget": 1000,
"fundingSource": "GUC",
"capacity": 50,
"registrationDeadline": "2025-12-12T13:00:00Z",
"status": "published"
}POST http://localhost:5001/api/registrations/register
Authorization: Bearer <user_token>
{
"eventType": "workshop",
"eventId": "<workshop_id_from_step_1>",
"name": "Test User",
"email": "test@guc.edu.eg",
"id": "12345"
}The chat will automatically activate when:
- The event's start time arrives (within 5 minutes)
- The scheduled task runs (every 5 minutes)
Or manually trigger it by:
# In the server directory
node -e "require('./services/chatService').manageEventChats().then(() => process.exit())"- Login to the application as a registered user
- Navigate to any page (home, events, etc.)
- Look for the minimized chat tab on the right side of the screen
- Click the chat tab to open it
- Send a test message
- Open another browser window/tab (incognito mode)
- Login as another registered user
- Verify that messages appear in real-time
- Click the minimize button (−) in the chat header
- Verify the chat collapses to a tab
- Click the tab to reopen
- Click the close button (×) in the chat header
- Verify the chat disappears completely
- Refresh the page
- Verify the chat reappears if still active
- Register for multiple events
- Wait for them to start
- Verify multiple minimized tabs appear
- Click each tab to switch between chats
- Verify your messages appear on the right with blue background
- Verify other users' messages appear on the left with white background
- Verify timestamps are displayed correctly
- Verify sender names are shown
- Try sending an empty message (should be disabled)
- Try sending a very long message (max 1000 chars)
- Verify character limit is enforced
Wait for the event end time or manually deactivate:
POST http://localhost:5001/api/chat/workshop/<event_id>/close
Authorization: Bearer <admin_token>Verify:
- Chat becomes read-only or closes
- New messages cannot be sent
- Chat tab disappears after refresh
Create a file test-chat.js in the server directory:
const axios = require('axios');
const API_URL = 'http://localhost:5001';
let authToken = '';
async function testChat() {
try {
// 1. Login
console.log('1. Logging in...');
const loginRes = await axios.post(`${API_URL}/api/auth/login`, {
email: 'test@guc.edu.eg',
password: 'password123'
});
authToken = loginRes.data.token;
console.log('✓ Logged in successfully');
// 2. Get active chats
console.log('\n2. Fetching active chats...');
const chatsRes = await axios.get(`${API_URL}/api/active-chats`, {
headers: { Authorization: `Bearer ${authToken}` }
});
console.log(`✓ Found ${chatsRes.data.length} active chat(s)`);
if (chatsRes.data.length === 0) {
console.log('⚠ No active chats found. Create and register for an event first.');
return;
}
// 3. Get messages for first chat
const firstChat = chatsRes.data[0];
console.log(`\n3. Getting messages for "${firstChat.eventName}"...`);
const messagesRes = await axios.get(
`${API_URL}/api/chat/${firstChat.eventType}/${firstChat.eventId}/messages`,
{ headers: { Authorization: `Bearer ${authToken}` } }
);
console.log(`✓ Found ${messagesRes.data.messages.length} message(s)`);
console.log('\n✅ All tests passed!');
} catch (error) {
console.error('❌ Test failed:', error.response?.data || error.message);
}
}
testChat();Run with: node test-chat.js
- Check browser console for errors
- Verify Socket.io connection: Look for "Socket connected" in console
- Check that event has started and status is correct
- Verify you're registered for the event
- Check browser console for Socket errors
- Verify authentication token is valid
- Check server logs for Socket.io events
- Ensure chat is still active
- Verify Socket.io connection is established
- Check CORS settings in server.js
- Try refreshing the page
- Check firewall/proxy settings
Test Socket.io connection:
// Check if socket service is connected
import socketService from './services/socketService';
console.log('Connected:', socketService.isConnected());
// Manually connect
socketService.connect();
// Test sending a message
socketService.sendMessage('workshop', 'EVENT_ID', 'Test message');When testing, watch for these logs:
✓ Socket connected
✓ User <userId> joined room workshop-<eventId>
✓ Message sent in room workshop-<eventId> by <userName>
✓ Activated chat for workshop: <eventName>
✓ Deactivated chat for workshop: <eventName>
Test with multiple users:
- Open 10+ browser tabs
- Login with different accounts in each
- All send messages simultaneously
- Verify all messages appear in real-time
- Check for lag or connection issues
- Try accessing chat without being registered
- Try sending messages without authentication
- Try XSS attacks in message text
- Verify message length limits
- Test with invalid event IDs