import { describe, it, beforeEach, expect } from 'bun:test'; import { makeMemDb } from '../../helpers/db'; import { AdminService } from '../../../src/services/admin'; import { AllowedGroups } from '../../../src/services/allowed-groups'; describe('AdminService - comandos básicos', () => { const envBackup = process.env; beforeEach(() => { process.env = { ...envBackup, NODE_ENV: 'test', ADMIN_USERS: '34600123456' }; const memdb = makeMemDb(); (AdminService as any).dbInstance = memdb; (AllowedGroups as any).dbInstance = memdb; }); it('rechaza a usuarios no admin', async () => { const out = await AdminService.handle({ sender: '34999888777', groupId: 'g1@g.us', message: '/admin pendientes' }); expect(out.length).toBe(1); expect(out[0].message.toLowerCase()).toContain('no estás autorizado'); }); it('lista pendientes', async () => { AllowedGroups.upsertPending('a@g.us', 'A', 'tester'); AllowedGroups.upsertPending('b@g.us', 'B', 'tester'); const out = await AdminService.handle({ sender: '34600123456', groupId: 'g1@g.us', message: '/admin pendientes' }); expect(out.length).toBe(1); expect(out[0].message).toContain('Grupos pendientes'); expect(out[0].message).toContain('a@g.us'); expect(out[0].message).toContain('b@g.us'); }); it('habilitar-aquí en grupo', async () => { const out = await AdminService.handle({ sender: '34600123456', groupId: 'g1@g.us', message: '/admin habilitar-aquí' }); expect(out.length).toBe(1); expect(AllowedGroups.isAllowed('g1@g.us')).toBe(true); }); it('allow-group habilita explícitamente', async () => { const out = await AdminService.handle({ sender: '34600123456', groupId: '1234567890@s.whatsapp.net', message: '/admin allow-group g2@g.us' }); expect(out.length).toBe(1); expect(AllowedGroups.isAllowed('g2@g.us')).toBe(true); }); });