|
|
|
@ -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
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|