|
|
@ -335,4 +335,115 @@ describe('WebhookServer', () => {
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
expect(mockAdd).toHaveBeenCalled();
|
|
|
|
expect(mockAdd).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should handle multiple dates in command (use last one as due date)', async () => {
|
|
|
|
|
|
|
|
const futureDate1 = getFutureDate(3);
|
|
|
|
|
|
|
|
const futureDate2 = getFutureDate(5);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
key: {
|
|
|
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
|
|
|
participant: 'sender-id@s.whatsapp.net'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
message: {
|
|
|
|
|
|
|
|
conversation: `/tarea nueva Test task ${futureDate1} some text ${futureDate2}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(console.log).toHaveBeenCalledWith(
|
|
|
|
|
|
|
|
'✅ Successfully parsed command:',
|
|
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
|
|
description: `Test task ${futureDate1} some text`,
|
|
|
|
|
|
|
|
dueDate: futureDate2
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should ignore past dates as due dates', async () => {
|
|
|
|
|
|
|
|
const pastDate = '2020-01-01';
|
|
|
|
|
|
|
|
const futureDate = getFutureDate(2);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
key: {
|
|
|
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
|
|
|
participant: 'sender-id@s.whatsapp.net'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
message: {
|
|
|
|
|
|
|
|
conversation: `/tarea nueva Test task ${pastDate} more text ${futureDate}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(console.log).toHaveBeenCalledWith(
|
|
|
|
|
|
|
|
'✅ Successfully parsed command:',
|
|
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
|
|
description: `Test task ${pastDate} more text`,
|
|
|
|
|
|
|
|
dueDate: futureDate
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should handle multiple past dates correctly', async () => {
|
|
|
|
|
|
|
|
const pastDate1 = '2020-01-01';
|
|
|
|
|
|
|
|
const pastDate2 = '2021-01-01';
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
key: {
|
|
|
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
|
|
|
participant: 'sender-id@s.whatsapp.net'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
message: {
|
|
|
|
|
|
|
|
conversation: `/tarea nueva Test task ${pastDate1} and ${pastDate2}`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(console.log).toHaveBeenCalledWith(
|
|
|
|
|
|
|
|
'✅ Successfully parsed command:',
|
|
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
|
|
description: `Test task ${pastDate1} and ${pastDate2}`,
|
|
|
|
|
|
|
|
dueDate: 'none'
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('should handle mixed valid and invalid date formats', async () => {
|
|
|
|
|
|
|
|
const futureDate = getFutureDate(2);
|
|
|
|
|
|
|
|
const payload = {
|
|
|
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
key: {
|
|
|
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
|
|
|
participant: 'sender-id@s.whatsapp.net'
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
message: {
|
|
|
|
|
|
|
|
conversation: `/tarea nueva Test task 2023-13-01 (invalid) ${futureDate} 25/12/2023 (invalid)`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(console.log).toHaveBeenCalledWith(
|
|
|
|
|
|
|
|
'✅ Successfully parsed command:',
|
|
|
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
|
|
|
description: 'Test task 2023-13-01 (invalid) 25/12/2023 (invalid)',
|
|
|
|
|
|
|
|
dueDate: futureDate
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|