From 37db7b283daef2c946c0d4513b376a30ef6b80e9 Mon Sep 17 00:00:00 2001 From: borja Date: Mon, 29 Sep 2025 11:10:17 +0200 Subject: [PATCH] fix: asegurar grupo existente en DB; actualizar prueba de gating Co-authored-by: aider (openrouter/openai/gpt-5) --- src/services/group-sync.ts | 2 ++ tests/unit/server/enforce-gating.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) 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 () => {