4.4 KiB
4.4 KiB
Pager Socket.IO Testing Guide
Quick Start
-
Start your NestJS server:
npm run start:dev -
Open the test page:
- Open
test-pager-socket.htmlin your web browser - Or serve it via a simple HTTP server:
# Using Python python3 -m http.server 8080 # Then open http://localhost:8080/test-pager-socket.html # Using Node.js (if you have http-server installed) npx http-server -p 8080
- Open
Testing Scenarios
Scenario 1: Test as Restaurant Admin/Staff
-
Get your admin JWT token:
- Login as admin via your API to get the JWT token
- Example:
curl -X POST http://localhost:4000/admin/auth/login \ -H "Content-Type: application/json" \ -d '{ "email": "admin@example.com", "password": "password" }' - Copy the
accessTokenfrom the response
-
Connect to the server:
- Enter server URL:
http://localhost:4000 - Enter your admin JWT token in the "Admin Token" field
- Click "Connect"
- Enter server URL:
-
Join restaurant room:
- Select "Restaurant (Admin/Staff)" from User Type
- Click "Join Room"
- The restaurant ID will be automatically extracted from your token
-
Create a pager request (via API):
curl -X POST http://localhost:4000/public/pager \ -H "Content-Type: application/json" \ -H "X-Slug: your-restaurant-slug" \ -d '{ "tableNumber": "5", "message": "Need assistance" }' -
Observe the event:
- You should see
pager:createdevent in the Events Log
- You should see
Scenario 2: Test as Public User
-
Create a pager request first (to get cookie ID):
curl -X POST http://localhost:4000/public/pager \ -H "Content-Type: application/json" \ -H "X-Slug: your-restaurant-slug" \ -d '{ "tableNumber": "3", "message": "Need water" }' \ -c cookies.txt -
Get the cookie ID:
- Check the response or cookies.txt file for
pagerIdcookie value
- Check the response or cookies.txt file for
-
Connect and join session:
- Connect to the server
- Select "Session (Public User)" from User Type
- Enter the cookie ID from step 2
- Click "Join Room"
-
Update pager status (via API as admin):
curl -X PATCH http://localhost:4000/admin/pager/{pagerId}/status \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \ -d '{ "status": "acknowledged" }' -
Observe the event:
- You should see
pager:status:updatedevent in the Events Log
- You should see
Socket Events Reference
Client → Server Events
| Event | Payload | Description |
|---|---|---|
join:restaurant |
{} (empty, restId extracted from token) |
Join restaurant room for admin/staff. Requires authentication via JWT token in connection auth |
join:session |
{ cookieId: string } |
Join session room for public user |
leave:room |
{ room: string } |
Leave a specific room |
Note: For join:restaurant, the restaurant ID is automatically extracted from the authenticated admin's JWT token. You must provide the token when connecting:
const socket = io('http://localhost:4000/pager', {
auth: {
token: 'your-jwt-token-here' // or 'Bearer your-jwt-token-here'
}
});
Server → Client Events
| Event | Payload | Description |
|---|---|---|
pager:created |
{ pager: {...} } |
New pager request created |
pager:status:updated |
{ pager: {...} } |
Pager status updated |
joined |
{ room: string, message: string } |
Successfully joined a room |
left |
{ room: string, message: string } |
Successfully left a room |
error |
{ message: string } |
Error occurred |
Room Names
- Restaurant Room:
restaurant:{restId} - Session Room:
cookie:{cookieId}
Testing Tips
- Open multiple browser tabs/windows to simulate multiple clients
- Use browser DevTools to inspect WebSocket connections
- Check server logs to see gateway activity
- Test reconnection by disconnecting and reconnecting
- Test room isolation by joining different rooms in different tabs
Troubleshooting
- Connection fails: Check if server is running on the correct port
- No events received: Verify you've joined the correct room
- CORS errors: Ensure CORS is enabled in your NestJS app (already configured in gateway)
- Events not showing: Check browser console for errors