|
|
|
|
@ -108,4 +108,111 @@ describe('WebhookServer - /admin aprobación en modo enforce', () => {
|
|
|
|
|
const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'another-group@g.us'`).get() as any;
|
|
|
|
|
expect(row == null).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admin puede habilitar el grupo actual con alias /admin enable', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'new-group-alias@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/admin enable' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
|
|
// Debe haber respuesta de confirmación encolada
|
|
|
|
|
expect(SimulatedResponseQueue.get().length).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
|
|
// El grupo debe figurar como allowed
|
|
|
|
|
const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'new-group-alias@g.us'`).get() as any;
|
|
|
|
|
expect(row && String(row.status)).toBe('allowed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admin puede deshabilitar el grupo actual con alias /admin disable', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'disable-group@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/admin disable' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
|
|
expect(SimulatedResponseQueue.get().length).toBeGreaterThan(0);
|
|
|
|
|
|
|
|
|
|
const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'disable-group@g.us'`).get() as any;
|
|
|
|
|
expect(row && String(row.status)).toBe('blocked');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admin puede permitir un grupo por JID con alias /admin allow <jid>', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'some-group@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/admin allow target-allow@g.us' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
|
|
const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'target-allow@g.us'`).get() as any;
|
|
|
|
|
expect(row && String(row.status)).toBe('allowed');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admin puede bloquear un grupo por JID con alias /admin block <jid>', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'some-group@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/admin block target-block@g.us' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
|
|
const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'target-block@g.us'`).get() as any;
|
|
|
|
|
expect(row && String(row.status)).toBe('blocked');
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('admin puede ver pendientes con alias /admin pending', async () => {
|
|
|
|
|
const payload = {
|
|
|
|
|
event: 'messages.upsert',
|
|
|
|
|
instance: 'test-instance',
|
|
|
|
|
data: {
|
|
|
|
|
key: {
|
|
|
|
|
remoteJid: 'some-group@g.us',
|
|
|
|
|
participant: '1234567890@s.whatsapp.net'
|
|
|
|
|
},
|
|
|
|
|
message: { conversation: '/admin pending' }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const res = await WebhookServer.handleRequest(createTestRequest(payload));
|
|
|
|
|
expect(res.status).toBe(200);
|
|
|
|
|
|
|
|
|
|
const out = SimulatedResponseQueue.get();
|
|
|
|
|
expect(out.length).toBe(1);
|
|
|
|
|
expect(String(out[0].message).toLowerCase()).toContain('no hay grupos pendientes');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|