mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-18 21:16:47 +00:00
7078ac7a4d
Client CI was red on this branch while dev was green, and no client file had changed. The 536 test files all passed; the job failed on three unhandled rejections, all `window is not defined` from MDashWidgets, attributed to whichever case happened to be running when they landed. The widget fetches api.frankfurter.dev directly and sets state from both handlers with no unmount guard. MSW runs with onUnhandledRequest: 'warn', so that request was never intercepted: it left the runner, came back after the environment was gone, and React tried to schedule an update against a torn down tree. Load dependent by construction, which is why dev happened to pass. Two halves, because either alone leaves the other broken. The widget now aborts in flight work on unmount and on refetch, and treats an abort as "no one is waiting" rather than as a failure to report. That matters outside the runner too: this is a third party call on a mobile screen a user can leave immediately. The handler set gains the third party endpoints the app calls directly rather than through /api, so no suite reaches the real host. An empty rate list is the shape the widget already handles. Also clears twenty more test files, each at its root cause. Two more were passing for the wrong reason: oidc.service.test.ts built AuthService with an AtlasService in the membership slot, undefined for userCleanup and mailer, and the mailer stub in the tokens slot, the same shift admin.service.test.ts had. And CAL-010 claims to serialise a flight byte for byte, but createReservation ignores reservation_time, so the row is written with a null time and CalendarService drops it: the recorded snapshot is truthful about the data the case builds and silent about the flight it advertises.
67 lines
3.2 KiB
TypeScript
67 lines
3.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import type { TrekWsPayload, TrekWsUserEventName } from '@trek/shared';
|
|
|
|
const { broadcast, broadcastToUser } = vi.hoisted(() => ({
|
|
broadcast: vi.fn(),
|
|
broadcastToUser: vi.fn(),
|
|
}));
|
|
vi.mock('../../../src/websocket', () => ({ broadcast, broadcastToUser }));
|
|
|
|
import { RealtimeService } from '../../../src/nest/realtime/realtime.service';
|
|
|
|
const svc = new RealtimeService();
|
|
|
|
/**
|
|
* These cases exercise argument pass-through, not payload shape, so they hand
|
|
* the facade only the fields their assertions read. The registry contract asks
|
|
* for more (`vacay:invite` for a `from`, `notification:new` for a
|
|
* `notification`); filling that in would put data into the recorded call that
|
|
* nothing here checks, so the shortcut is named instead of padded out.
|
|
*/
|
|
function partialUserPayload<E extends TrekWsUserEventName>(
|
|
payload: { type: E } & Partial<TrekWsPayload<E>>,
|
|
): { type: E } & TrekWsPayload<E> {
|
|
return payload as { type: E } & TrekWsPayload<E>;
|
|
}
|
|
|
|
beforeEach(() => vi.clearAllMocks());
|
|
|
|
describe('RealtimeService', () => {
|
|
it('broadcast delegates every argument to the websocket module untouched', () => {
|
|
svc.broadcast('7', 'place:created', { place: { id: 1 } }, '42', 9);
|
|
expect(broadcast).toHaveBeenCalledTimes(1);
|
|
expect(broadcast).toHaveBeenCalledWith('7', 'place:created', { place: { id: 1 } }, '42', 9);
|
|
});
|
|
|
|
it('broadcast preserves the caller argument arity exactly (no undefined padding)', () => {
|
|
// The excludeSid truthiness quirk and onlyUserId `!= null` check live in
|
|
// websocket.ts — the facade must not normalize, default, or pad anything
|
|
// on the way through: existing suites assert exact 3/4/5-arg call shapes.
|
|
svc.broadcast(7, 'day:updated', { day: null });
|
|
expect(broadcast.mock.calls[0]).toEqual([7, 'day:updated', { day: null }]);
|
|
svc.broadcast(7, 'day:updated', { day: null }, undefined);
|
|
expect(broadcast.mock.calls[1]).toEqual([7, 'day:updated', { day: null }, undefined]);
|
|
expect(broadcast.mock.calls[1].length).toBe(4);
|
|
});
|
|
|
|
it('broadcastToUser delegates every argument untouched', () => {
|
|
const payload = partialUserPayload({ type: 'vacay:invite', planId: 3 });
|
|
svc.broadcastToUser(5, payload, '11');
|
|
expect(broadcastToUser).toHaveBeenCalledTimes(1);
|
|
expect(broadcastToUser).toHaveBeenCalledWith(5, payload, '11');
|
|
// Same object reference — the facade must not clone or re-envelope.
|
|
expect(broadcastToUser.mock.calls[0][1]).toBe(payload);
|
|
});
|
|
|
|
it('per-file vi.mock of src/websocket flows through the facade (call-time delegation)', () => {
|
|
// The 106 existing suites mock src/websocket by path and assert on those
|
|
// mocks; this pins that a facade constructed before/after the mock still
|
|
// routes through the mocked module functions rather than captured bindings.
|
|
const late = new RealtimeService();
|
|
late.broadcast('1', 'todo:created', { item: {} }, undefined);
|
|
late.broadcastToUser(2, partialUserPayload({ type: 'notification:new' }));
|
|
expect(broadcast).toHaveBeenCalledWith('1', 'todo:created', { item: {} }, undefined);
|
|
expect(broadcastToUser).toHaveBeenCalledWith(2, { type: 'notification:new' });
|
|
});
|
|
});
|