mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-29 16:10:07 +00:00
test(atlas): settle the first CI round of the new Atlas tests
Client types: Array.at is past the lib target, typed mocks where a spy is called. Client lint: mock components named so hooks may run in them, state reported from effects instead of written into props, promises voided or awaited. Client tests: class order as passed, month names checked in Japanese whatever the ICU build, mesh vertex counts asserted by shape, the buffer growth case built from many small squares instead of one strip that took 15 s, the shooting star tests driving the sky's own schedule, and reduced motion mocked once so it no longer silences later tests. Server: the hidden-setting cases as it.each (no-await-in-loop), and the presence branches the realtime 100% threshold asks for.
This commit is contained in:
@@ -229,7 +229,8 @@ export class RealtimeGateway implements OnGatewayInit, OnGatewayConnection, OnGa
|
||||
* Writes the socket's session as active now, for a tab in front, at most
|
||||
* once per SESSION_TOUCH_INTERVAL_MS (the same pace the request check keeps).
|
||||
*/
|
||||
private async touchSession(socket: TrekWebSocket, now = Date.now()): Promise<void> {
|
||||
private async touchSession(socket: TrekWebSocket): Promise<void> {
|
||||
const now = Date.now();
|
||||
const session = sessionOf(socket);
|
||||
if (!session || !socketVisible(socket) || socket.readyState !== 1) return;
|
||||
if (now - (this.touchedAt.get(socket) ?? 0) < SESSION_TOUCH_INTERVAL_MS) return;
|
||||
|
||||
@@ -166,18 +166,20 @@ describe('AtlasPeopleService over a built manifest', () => {
|
||||
expect(badges.find((b) => b.id === 'flights-dateline')).toMatchObject({ earned: false, current: 0 });
|
||||
});
|
||||
|
||||
it('ATLAS2-REST-007: the opt-out reads as hidden in every spelling the settings store hands back, and nothing else does', async () => {
|
||||
for (const v of [true, 'true', 1, '1']) {
|
||||
userSettings = { atlas_hidden: v };
|
||||
expect(await people.isHidden(8)).toBe(true);
|
||||
}
|
||||
for (const v of [false, 'false', 0, '0', null, undefined, 'yes']) {
|
||||
userSettings = { atlas_hidden: v };
|
||||
expect(await people.isHidden(8)).toBe(false);
|
||||
}
|
||||
it.each([true, 'true', 1, '1'])('ATLAS2-REST-007: the opt-out stored as %j reads as hidden', async (v) => {
|
||||
userSettings = { atlas_hidden: v };
|
||||
expect(await people.isHidden(8)).toBe(true);
|
||||
expect(settings.getUserSettings).toHaveBeenCalledWith(8);
|
||||
});
|
||||
|
||||
it.each([false, 'false', 0, '0', null, undefined, 'yes'])(
|
||||
'ATLAS2-REST-007b: a setting of %j does not hide anyone',
|
||||
async (v) => {
|
||||
userSettings = { atlas_hidden: v };
|
||||
expect(await people.isHidden(8)).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
it('ATLAS2-REST-008: the comparison is on while the admin stored nothing or anything but false', async () => {
|
||||
settings.getAppSetting.mockResolvedValueOnce(null);
|
||||
expect(await people.compareEnabled()).toBe(true);
|
||||
|
||||
@@ -811,4 +811,29 @@ describe('RealtimeGateway presence', () => {
|
||||
gw.onModuleDestroy();
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('WSGW-PRES-005: a presence frame without a body counts as in front, and a closing socket writes nothing', async () => {
|
||||
const quiet = socket();
|
||||
const closing = socket();
|
||||
registerSocket(quiet, { id: 18, username: 'q' } as User, 'sess-q');
|
||||
registerSocket(closing, { id: 19, username: 'c' } as User, 'sess-c');
|
||||
(closing as { readyState: number }).readyState = 2;
|
||||
const gw = await gateway();
|
||||
|
||||
await gw.handlePresence(undefined as never, quiet);
|
||||
await gw.handlePresence({ visible: true }, closing);
|
||||
|
||||
expect(touchLastSeen.mock.calls.map(([id]) => id)).toEqual(['sess-q']);
|
||||
});
|
||||
|
||||
it('WSGW-PRES-006: a write that fails with something other than an Error is logged as it is', async () => {
|
||||
const ws = socket();
|
||||
registerSocket(ws, { id: 20, username: 'r' } as User, 'sess-r');
|
||||
touchLastSeen.mockRejectedValueOnce('locked');
|
||||
const gw = await gateway();
|
||||
|
||||
await gw.handlePresence({ visible: true }, ws);
|
||||
|
||||
expect(logError).toHaveBeenCalledWith('ws presence touch failed: locked');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user