|
|
|
@ -223,6 +223,69 @@ describe('WebhookServer', () => {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('/tarea command logging', () => {
|
|
|
|
|
let consoleSpy: any;
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
consoleSpy = mock(() => {});
|
|
|
|
|
console.log = consoleSpy;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
|
consoleSpy.mockRestore();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should log basic /tarea command', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'group123@g.us',
|
|
|
|
|
participant: 'user123@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/tarea test' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
expect(consoleSpy).toHaveBeenCalledWith(
|
|
|
|
|
expect.stringContaining('/tarea command received:'),
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
command: '/tarea',
|
|
|
|
|
arguments: 'test',
|
|
|
|
|
dueDate: 'none',
|
|
|
|
|
fullMessage: '/tarea test'
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should log command with due date', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'group123@g.us',
|
|
|
|
|
participant: 'user123@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/tarea due:2025-04-30 Finish project' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
|
|
|
|
|
expect(consoleSpy).toHaveBeenCalledWith(
|
|
|
|
|
expect.stringContaining('/tarea command received:'),
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
dueDate: '2025-04-30',
|
|
|
|
|
arguments: 'due:2025-04-30 Finish project'
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should handle XSS/SQL injection attempts', async () => {
|
|
|
|
|
const maliciousMessage = `/tarea nueva <script>alert('xss')</script>'; DROP TABLE tasks; --`;
|
|
|
|
|
const payload = {
|
|
|
|
|