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(); + }); });