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(packing): pin the bag-totals ping in the RPC and MCP fan-out expectations

Claude700918d533d1
diff --git a/server/tests/unit/mcp/tools-packing-advanced.test.ts b/server/tests/unit/mcp/tools-packing-advanced.test.ts
index 0fa111948..8fa1cf15d 100644
--- a/server/tests/unit/mcp/tools-packing-advanced.test.ts
+++ b/server/tests/unit/mcp/tools-packing-advanced.test.ts
@@ -565,7 +565,11 @@ describe('Tool: bulk_import_packing', () => {
expect(data.items).toHaveLength(items.length);
expect(data.items[0].name).toBe('Passport');
expect(broadcastMock).toHaveBeenCalledWith(trip.id, 'packing:created', expect.objectContaining({ item: expect.any(Object) }));
- expect(broadcastMock).toHaveBeenCalledTimes(items.length);
+ // Plus ONE bag-totals ping for the whole import (#2191) — not one per
+ // item: it is content-free and each one costs every connected client a
+ // listBags round trip.
+ expect(broadcastMock).toHaveBeenCalledWith(String(trip.id), 'packing:bag-totals', {}, undefined);
+ expect(broadcastMock).toHaveBeenCalledTimes(items.length + 1);
});
});
diff --git a/server/tests/unit/packing/packing.rpc.test.ts b/server/tests/unit/packing/packing.rpc.test.ts
index 451a65f03..f94b7d3fa 100644
--- a/server/tests/unit/packing/packing.rpc.test.ts
+++ b/server/tests/unit/packing/packing.rpc.test.ts
@@ -199,16 +199,25 @@ describe('PackingRpc keeps private items off the room (#858)', () => {
it('PACKING-RPC-009 a common item is created for the whole room', async () => {
const f = build();
await f.host('db:write:packing').dispatch(req('packing.create', { tripId: 1, input: { name: 'Socks' } }), 42);
- expect(fanout(f.realtime)).toEqual([['packing:created', undefined]]);
+ // The trailing bag-totals ping is room-wide and content-free (#2191): bag
+ // weights are summed server-side, so every member has to re-read them even
+ // when the item itself is none of their business.
+ expect(fanout(f.realtime)).toEqual([
+ ['packing:created', undefined],
+ ['packing:bag-totals', undefined],
+ ]);
});
it('PACKING-RPC-010 a private item is created only for its owner and recipients', async () => {
const f = build();
f.data.createItem.mockReturnValueOnce({ id: 70, is_private: 1, owner_id: 42, recipients: [{ user_id: 7 }] });
await f.host('db:write:packing').dispatch(req('packing.create', { tripId: 1, input: { name: 'Gift', is_private: true } }), 42);
+ // The item goes only to its viewers; the weight ping goes to the room and
+ // says nothing at all (#2191) — that is exactly what makes it safe here.
expect(fanout(f.realtime)).toEqual([
['packing:created', 42],
['packing:created', 7],
+ ['packing:bag-totals', undefined],
]);
});
@@ -256,9 +265,12 @@ describe('PackingRpc keeps private items off the room (#858)', () => {
const f = build();
f.data.deleteItem.mockReturnValueOnce({ id: 70, is_private: 1, owner_id: 42, recipients: [{ user_id: 7 }] });
await f.host('db:write:packing').dispatch(req('packing.delete', { tripId: 1, itemId: 70 }), 42);
+ // Same split as the create above: private item to its viewers, content-free
+ // weight ping to the room (#2191).
expect(fanout(f.realtime)).toEqual([
['packing:deleted', 42],
['packing:deleted', 7],
+ ['packing:bag-totals', undefined],
]);
});