From fa08689ee09dfac01bd5ff0ef6a27b53dfc093b5 Mon Sep 17 00:00:00 2001 From: borja Date: Sat, 6 Sep 2025 17:23:42 +0200 Subject: [PATCH] =?UTF-8?q?test:=20a=C3=B1adir=20tests=20para=20alias=20/t?= =?UTF-8?q?,=20DM=20y=20cola=20de=20respuestas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/openai/gpt-5) --- tests/unit/server.test.ts | 40 +++++++++++++++++++++++++++++ tests/unit/services/command.test.ts | 11 +++++--- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index d346a9c..5f9beff 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -702,5 +702,45 @@ describe('WebhookServer', () => { expect(response.status).toBe(200); expect(SimulatedResponseQueue.getQueue().length).toBeGreaterThan(0); }); + + test('should accept /t alias and process command', async () => { + const payload = { + event: 'messages.upsert', + instance: 'test-instance', + data: { + key: { + remoteJid: 'group-id@g.us', + participant: '1234567890@s.whatsapp.net' + }, + message: { conversation: '/t n Tarea alias hoy' } + } + }; + const request = createTestRequest(payload); + const response = await WebhookServer.handleRequest(request); + expect(response.status).toBe(200); + expect(SimulatedResponseQueue.getQueue().length).toBeGreaterThan(0); + }); + + test('should never send responses to the group (DM only policy)', async () => { + const payload = { + event: 'messages.upsert', + instance: 'test-instance', + data: { + key: { + remoteJid: 'group-id@g.us', + participant: '1234567890@s.whatsapp.net' + }, + message: { conversation: '/t n Probar silencio grupo mañana' } + } + }; + const request = createTestRequest(payload); + await WebhookServer.handleRequest(request); + + const out = SimulatedResponseQueue.getQueue(); + expect(out.length).toBeGreaterThan(0); + for (const r of out) { + expect(r.recipient.endsWith('@g.us')).toBe(false); + } + }); }); }); diff --git a/tests/unit/services/command.test.ts b/tests/unit/services/command.test.ts index 1ffac6f..a38d51d 100644 --- a/tests/unit/services/command.test.ts +++ b/tests/unit/services/command.test.ts @@ -31,15 +31,20 @@ describe('CommandService', () => { expect(responses).toEqual([]); }); - test('should handle tarea nueva: crea y responde con id y descripción', async () => { + test('acepta alias /t y responde con formato compacto', async () => { const responses = await CommandService.handle({ ...testContextBase, - message: '/tarea nueva Test task' + message: '/t n Test task' }); expect(responses.length).toBe(1); expect(responses[0].recipient).toBe('1234567890'); - expect(responses[0].message).toMatch(/^✅ Tarea \d+ creada: "Test task"/); + // Debe empezar con "✅ " + expect(responses[0].message).toMatch(/^✅ \d+ /); + // Debe contener la descripción en negrita compacta + expect(responses[0].message).toContain('*Test task*'); + // No debe usar el texto antiguo "Tarea creada" + expect(responses[0].message).not.toMatch(/Tarea \d+ creada/); }); test('should return error response on failure', async () => {