diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index dd1a5a1..82c6b89 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -811,6 +811,8 @@ export class GroupSyncService { } catch {} try { + // Asegurar existencia del grupo en DB (FKs) antes de reconciliar + this.ensureGroupExists(groupId); const snapshot = await (this as any).fetchGroupMembersFromAPI(groupId); return this.reconcileGroupMembers(groupId, snapshot); } catch (e) { diff --git a/tests/unit/server/enforce-gating.test.ts b/tests/unit/server/enforce-gating.test.ts index 6143b85..d4341cf 100644 --- a/tests/unit/server/enforce-gating.test.ts +++ b/tests/unit/server/enforce-gating.test.ts @@ -79,9 +79,9 @@ describe('WebhookServer - enforce gating (modo=enforce)', () => { // No debe haber respuestas encoladas (retorno temprano) expect(SimulatedResponseQueue.get().length).toBe(0); - // allowed_groups no contiene allowed para ese grupo + // allowed_groups no contiene allowed para ese grupo (get() devuelve null cuando no hay filas) const row = testDb.query(`SELECT status FROM allowed_groups WHERE group_id = 'blocked-group@g.us'`).get() as any; - expect(row).toBeUndefined(); + expect(row == null).toBe(true); }); test('permite mensaje en grupo allowed y procesa comando', async () => {