From b0f5a83b443dc12745e25232263d74fd6545e40e Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Fri, 2 May 2025 17:04:22 +0200 Subject: [PATCH] fix: update test to use dynamic dates instead of hardcoded ones --- tests/unit/server.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/unit/server.test.ts b/tests/unit/server.test.ts index 476c4c4..4fede56 100644 --- a/tests/unit/server.test.ts +++ b/tests/unit/server.test.ts @@ -223,6 +223,12 @@ describe('WebhookServer', () => { } }); + function getFutureDate(days: number): string { + const date = new Date(); + date.setDate(date.getDate() + days); + return date.toISOString().split('T')[0]; + } + describe('/tarea command logging', () => { let consoleSpy: any; @@ -268,6 +274,7 @@ describe('WebhookServer', () => { }); test('should log command with due date', async () => { + const futureDate = getFutureDate(3); // Get date 3 days in future const payload = { event: 'messages.upsert', instance: 'test-instance', @@ -277,7 +284,7 @@ describe('WebhookServer', () => { participant: 'user123@s.whatsapp.net' }, message: { - conversation: '/tarea nueva Finish project @user2 2025-04-30', + conversation: `/tarea nueva Finish project @user2 ${futureDate}`, contextInfo: { mentionedJid: ['user2@s.whatsapp.net'] } @@ -287,7 +294,7 @@ describe('WebhookServer', () => { await WebhookServer.handleRequest(createTestRequest(payload)); - // Verify the two command-related log calls (first log is skipped in test mode) + // Verify the two command-related log calls expect(consoleSpy).toHaveBeenCalledTimes(2); // First call should be the command detection @@ -296,7 +303,7 @@ describe('WebhookServer', () => { timestamp: expect.any(String), from: 'user123@s.whatsapp.net', group: 'group123@g.us', - rawMessage: '/tarea nueva Finish project @user2 2025-04-30' + rawMessage: `/tarea nueva Finish project @user2 ${futureDate}` }); // Second call should be the successful parsing @@ -304,7 +311,7 @@ describe('WebhookServer', () => { expect(consoleSpy.mock.calls[1][1]).toEqual({ action: 'nueva', description: 'Finish project @user2', - dueDate: '2025-04-30', + dueDate: futureDate, mentionCount: 1 }); });