From de90e6d6c33d1731ebcd5776cd5c3d92ef23c32c Mon Sep 17 00:00:00 2001 From: borja Date: Fri, 5 Sep 2025 11:07:31 +0200 Subject: [PATCH] =?UTF-8?q?test:=20a=C3=B1adir=20pruebas=20para=20manejo?= =?UTF-8?q?=20de=20ID=20de=20remitente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) --- tests/unit/server.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index 6d91cbc..a0ac4ca 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -446,4 +446,40 @@ describe('WebhookServer', () => { }) ); }); + + test('should normalize sender ID before processing', async () => { + const payload = { + event: 'messages.upsert', + instance: 'test-instance', + data: { + key: { + remoteJid: 'group-id@g.us', + participant: '1234567890:12@s.whatsapp.net' // ID with participant + }, + message: { conversation: '/tarea nueva Test' } + } + }; + const request = createTestRequest(payload); + const response = await WebhookServer.handleRequest(request); + expect(response.status).toBe(200); + expect(mockAdd).toHaveBeenCalled(); + }); + + test('should ignore messages with invalid sender ID', async () => { + const payload = { + event: 'messages.upsert', + instance: 'test-instance', + data: { + key: { + remoteJid: 'group-id@g.us', + participant: 'invalid-id!' // Invalid ID + }, + message: { conversation: '/tarea nueva Test' } + } + }; + const request = createTestRequest(payload); + const response = await WebhookServer.handleRequest(request); + expect(response.status).toBe(200); + expect(mockAdd).not.toHaveBeenCalled(); + }); });