Context
src/presence.js was added in #14 but has no tests. The existing test suite lives in test/test.js.
What to test
trackPresence(socket, userId) — emits presence:change with status: 'online' when first socket for a user connects
trackPresence — does not re-emit presence:change if the same user connects from a second tab (already online)
- Disconnect — emits
presence:change with status: 'offline' only when the last socket for a user disconnects
- Disconnect — does not emit offline if the user still has another socket open
setPresence(userId, 'away') — emits presence:change with status: 'away'
setPresence() — throws if userId is not tracked
setPresence() — throws if status is invalid
getPresence(userId) — returns { status: 'offline', lastSeen: null } for unknown user
getRoomPresence(roomId) — returns a map of all participants' presence
Setup tip
Use socket.io-client (already a devDependency) to spin up a real server and connect test clients, similar to the existing auth tests.
Context
src/presence.jswas added in #14 but has no tests. The existing test suite lives intest/test.js.What to test
trackPresence(socket, userId)— emitspresence:changewithstatus: 'online'when first socket for a user connectstrackPresence— does not re-emitpresence:changeif the same user connects from a second tab (already online)presence:changewithstatus: 'offline'only when the last socket for a user disconnectssetPresence(userId, 'away')— emitspresence:changewithstatus: 'away'setPresence()— throws if userId is not trackedsetPresence()— throws if status is invalidgetPresence(userId)— returns{ status: 'offline', lastSeen: null }for unknown usergetRoomPresence(roomId)— returns a map of all participants' presenceSetup tip
Use
socket.io-client(already a devDependency) to spin up a real server and connect test clients, similar to the existing auth tests.