From 9f339ad21816de8c616cce2636dcee7eb8c7e83f Mon Sep 17 00:00:00 2001 From: borja Date: Fri, 5 Sep 2025 15:59:01 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20hacer=20p=C3=BAblico=20el=20cache=20de?= =?UTF-8?q?=20grupos=20para=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) --- src/services/group-sync.ts | 13 ++++++++----- tests/unit/services/group-sync.test.ts | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/services/group-sync.ts b/src/services/group-sync.ts index 834434d..1165b4f 100644 --- a/src/services/group-sync.ts +++ b/src/services/group-sync.ts @@ -3,7 +3,7 @@ import { db } from '../db'; const env = process.env; // In-memory cache for active groups -const activeGroupsCache = new Map(); // groupId -> groupName +// const activeGroupsCache = new Map(); // groupId -> groupName /** * Represents a group from the Evolution API response @@ -36,6 +36,9 @@ export class GroupSyncService { // Static property for DB instance injection (defaults to global db) static dbInstance: Database = db; + // In-memory cache for active groups (made public for tests) + public static readonly activeGroupsCache = new Map(); // groupId -> groupName + /** * Gets the sync interval duration in milliseconds. * @@ -199,11 +202,11 @@ export class GroupSyncService { private static cacheActiveGroups(): void { const groups = this.dbInstance.prepare('SELECT id, name FROM groups WHERE active = TRUE').all(); - activeGroupsCache.clear(); + this.activeGroupsCache.clear(); for (const group of groups) { - activeGroupsCache.set(group.id, group.name); + this.activeGroupsCache.set(group.id, group.name); } - console.log(`Cached ${activeGroupsCache.size} active groups`); + console.log(`Cached ${this.activeGroupsCache.size} active groups`); } private static getActiveGroupsCount(): number { @@ -330,6 +333,6 @@ export class GroupSyncService { * @returns True if the group is active, false otherwise. */ static isGroupActive(groupId: string): boolean { - return activeGroupsCache.has(groupId); + return this.activeGroupsCache.has(groupId); } } diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index 3701a1e..44ee12c 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -149,7 +149,7 @@ describe('GroupSyncService', () => { describe('isGroupActive', () => { beforeEach(() => { // Clear cache and add test groups - GroupSyncService['activeGroupsCache'].clear(); + GroupSyncService.activeGroupsCache.clear(); db.exec('DELETE FROM groups'); db.exec("INSERT INTO groups (id, name, active) VALUES ('active-group', 'Active Group', 1)"); db.exec("INSERT INTO groups (id, name, active) VALUES ('inactive-group', 'Inactive Group', 0)");