|
|
|
|
@ -482,4 +482,40 @@ describe('WebhookServer', () => {
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
expect(mockAdd).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should ensure user exists and use normalized ID', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/tarea nueva Test' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const request = createTestRequest(payload);
|
|
|
|
|
const response = await WebhookServer.handleRequest(request);
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
expect(mockAdd).toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('should ignore messages if user creation fails', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'group-id@g.us',
|
|
|
|
|
participant: null // Invalid participant
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/tarea nueva Test' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const request = createTestRequest(payload);
|
|
|
|
|
const response = await WebhookServer.handleRequest(request);
|
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
|
expect(mockAdd).not.toHaveBeenCalled();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|