Skip to content

test: add tests for presence system #17

Description

@Aaromalpm

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions