Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

test(realtime): cover forgetting a closed session after a minute

Maurice7f3ead2c8594
diff --git a/server/tests/unit/nest/realtime.revocation.test.ts b/server/tests/unit/nest/realtime.revocation.test.ts
index 67e04eda4..deb442cf8 100644
--- a/server/tests/unit/nest/realtime.revocation.test.ts
+++ b/server/tests/unit/nest/realtime.revocation.test.ts
@@ -1,5 +1,5 @@
/**
- * WSREV-001 to WSREV-017: a socket is let into a room with one access check,
+ * WSREV-001 to WSREV-018: a socket is let into a room with one access check,
* so the writes that end access ask the sockets already in again
* (recheckTripAccess, recheckJourneyAccess), and the sockets of a user whose
* sessions ended, or of every user once the database was replaced, are
@@ -21,6 +21,7 @@ import {
registerSocket,
roomAccessSlot,
roomsSlot,
+ sessionClosed,
setServer,
type RoomAccess,
type TrekWebSocket,
@@ -219,6 +220,14 @@ describe('closeSockets', () => {
expect(theirs.sent).toContainEqual(expect.objectContaining({ type: 'journey:book:peers' }));
});
+ it('WSREV-018: a session whose sockets were closed is remembered for a minute, then forgotten', () => {
+ const now = Date.now();
+ closeSockets(4001, 'Session ended', 1, 'sess-gone');
+ expect(sessionClosed('sess-gone', now)).toBe(true);
+ expect(sessionClosed('sess-never', now)).toBe(false);
+ expect(sessionClosed('sess-gone', now + 60_000)).toBe(false);
+ });
+
it('WSREV-017: one ended session closes its own sockets and those of no known session, never another device', async () => {
const ended = open(1, 'sess-a');
const otherDevice = open(1, 'sess-b');