Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(session): cover presence reset on engine replacement
Yudhi Armyndharis93b81fc3a4d3
diff --git a/src/modules/session/session.service.spec.ts b/src/modules/session/session.service.spec.tsindex 89691706d..bcbed441a 100644--- a/src/modules/session/session.service.spec.ts+++ b/src/modules/session/session.service.spec.ts@@ -5716,6 +5716,26 @@ describe('SessionService', () => {expect(mockEngine.setOnlinePresence).toHaveBeenNthCalledWith(2, false);});+ it('drops the own-presence preference and chat presence when the engine is replaced', async () => {+ const first = await startAndCaptureCallbacks();+ await service.setOnlinePresence('sess-uuid-1', false);+ first.onPresenceUpdate!({ chatId: '[email protected]', participants: [{ id: '[email protected]', state: 'composing' }] });+ expect(await service.getPresence('sess-uuid-1', '[email protected]')).not.toBeNull();++ await service.stop('sess-uuid-1');+ await service.start('sess-uuid-1');+ const calls = mockEngine.initialize.mock.calls as [EngineEventCallbacks][];+ expect(calls).toHaveLength(2);+ mockEngine.setOnlinePresence.mockClear();++ // The replacement engine's first open must not re-publish the previous engine's choice.+ calls[1][0].onReady!('628123', 'Alice');+ await flush();++ expect(mockEngine.setOnlinePresence).not.toHaveBeenCalled();+ expect(await service.getPresence('sess-uuid-1', '[email protected]')).toBeNull();+ });+it('does not publish own presence on ready when the caller never set one', async () => {const callbacks = await startAndCaptureCallbacks();mockEngine.setOnlinePresence.mockClear();