You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
|
import Database from 'bun:sqlite';
|
|
import { initializeDatabase } from '../../../src/db';
|
|
import { GroupSyncService } from '../../../src/services/group-sync';
|
|
|
|
describe('GroupSyncService - upsertGroups actualiza label en allowed_groups', () => {
|
|
const envBackup = process.env;
|
|
let memdb: Database;
|
|
|
|
beforeEach(() => {
|
|
process.env = { ...envBackup, NODE_ENV: 'test', WHATSAPP_COMMUNITY_ID: 'comm-1' };
|
|
memdb = new Database(':memory:');
|
|
initializeDatabase(memdb);
|
|
(GroupSyncService as any).dbInstance = memdb;
|
|
|
|
// Limpiar tablas
|
|
memdb.exec('DELETE FROM allowed_groups');
|
|
memdb.exec('DELETE FROM groups');
|
|
});
|
|
|
|
afterEach(() => {
|
|
memdb.close();
|
|
process.env = envBackup;
|
|
});
|
|
|
|
it('propaga subject como label aunque no exista fila previa', async () => {
|
|
await (GroupSyncService as any).upsertGroups([{ id: 'gg@g.us', subject: 'Grupo GG', linkedParent: 'comm-1' }]);
|
|
|
|
const row = memdb.query(`SELECT label, status FROM allowed_groups WHERE group_id = 'gg@g.us'`).get() as any;
|
|
expect(row).toBeDefined();
|
|
expect(String(row.label)).toBe('Grupo GG');
|
|
expect(String(row.status)).toBe('pending');
|
|
});
|
|
});
|