Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(baileys): pin the SVG block's order and the unbuilt echo
Yudhi Armyndharis7da887db9abf
diff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex ea936ba9c..f7e0a6ee9 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -291,10 +291,18 @@ describe('BaileysAdapter lifecycle & status', () => {it('blocks SVG decoding before the engine starts, whichever route reaches sharp first', async () => {// Sticker conversion and the thumbnail of every outbound image share one process-wide decoder, so the- // block cannot wait for the first sticker.+ // block cannot wait for the first sticker, and it has to be in place before the socket exists.+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access+ const makeWASocket = jest.requireMock('@whiskeysockets/baileys').default as jest.Mock;const block = jest.spyOn(messagingModule, 'blockSvgDecoding').mockResolvedValue(undefined);- await newAdapter().initialize(noopCallbacks({}));- expect(block).toHaveBeenCalledTimes(1);+ try {+ await newAdapter().initialize(noopCallbacks({}));+ expect(block).toHaveBeenCalledTimes(1);+ expect(makeWASocket).toHaveBeenCalled();+ expect(block.mock.invocationCallOrder[0]).toBeLessThan(makeWASocket.mock.invocationCallOrder[0]);+ } finally {+ block.mockRestore();+ }});it('captures phone/pushName and fires onReady on connection open', async () => {diff --git a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts b/src/engine/adapters/whatsapp-web-js.adapter.spec.tsindex 6d4a8f138..6a4208c8c 100644--- a/src/engine/adapters/whatsapp-web-js.adapter.spec.ts+++ b/src/engine/adapters/whatsapp-web-js.adapter.spec.ts@@ -3660,7 +3660,8 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()it('logs an own-send echo whose base cannot be built instead of dropping it silently', async () => {// The echo runs in an async function whose rejection holdWhileProcessing consumes, so an unreadable// `to` (a WhatsApp Web build renaming the field) vanished without a log line or the unhandled-rejection- // metric. The incoming handler logs the same defect; the echo must too, and still release its ticket.+ // metric. The incoming handler logs the same defect; the echo must too. It is not admitted either, since+ // its chat is unknown, so there is no ticket to settle.const adapter = new WhatsAppWebJsAdapter({sessionId: 'sess-echo-unreadable',sessionDataPath: './data/sessions',@@ -3694,6 +3695,7 @@ describe('WhatsAppWebJsAdapter inbound media (MEDIA_DOWNLOAD_ENABLED=false)', ()await new Promise(r => setImmediate(r));expect(onMessageCreate).not.toHaveBeenCalled();+ expect(admitInbound).not.toHaveBeenCalled();expect(errorSpy).toHaveBeenCalledWith('Error processing outgoing message', expect.stringContaining('endsWith'));});