From c8b4b5592b178d7666a34b4c0ff1532121c7988d Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Fri, 28 Mar 2025 16:27:52 +0100 Subject: [PATCH] fix: update test assertions for command logging --- src/server.ts | 12 ++++++---- tests/unit/server.test.ts | 50 +++++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/server.ts b/src/server.ts index aebcd49..84bf821 100644 --- a/src/server.ts +++ b/src/server.ts @@ -38,11 +38,13 @@ export class WebhookServer { return new Response('OK', { status: 200 }); } - console.log('â„šī¸ Incoming webhook request:', { - method: request.method, - path: url.pathname, - time: new Date().toISOString() - }); + if (process.env.NODE_ENV !== 'test') { + console.log('â„šī¸ Incoming webhook request:', { + method: request.method, + path: url.pathname, + time: new Date().toISOString() + }); + } // 1. Method validation if (request.method !== 'POST') { diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index feeb013..410ec1e 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -287,27 +287,35 @@ describe('WebhookServer', () => { await WebhookServer.handleRequest(createTestRequest(payload)); - // Verify the detection log - expect(consoleSpy).toHaveBeenCalledWith( - '🔍 Detected /tarea command:', - expect.objectContaining({ - timestamp: expect.any(String), - from: 'user123@s.whatsapp.net', - group: 'group123@g.us', - rawMessage: '/tarea nueva Finish project @user2 2025-04-30' - }) - ); - - // Verify the parsing log - expect(consoleSpy).toHaveBeenCalledWith( - '✅ Successfully parsed command:', - expect.objectContaining({ - action: 'nueva', - description: 'Finish project @user2', - dueDate: '2025-04-30', - mentionCount: 1 - }) - ); + // Verify all log calls in order + expect(consoleSpy.mock.calls).toEqual([ + [ + 'â„šī¸ Incoming webhook request:', + expect.objectContaining({ + method: 'POST', + path: '/', + time: expect.any(String) + }) + ], + [ + '🔍 Detected /tarea command:', + expect.objectContaining({ + timestamp: expect.any(String), + from: 'user123@s.whatsapp.net', + group: 'group123@g.us', + rawMessage: '/tarea nueva Finish project @user2 2025-04-30' + }) + ], + [ + '✅ Successfully parsed command:', + expect.objectContaining({ + action: 'nueva', + description: 'Finish project @user2', + dueDate: '2025-04-30', + mentionCount: 1 + }) + ] + ]); }); });