fix: hacer público el cache de grupos para tests

Co-authored-by: aider (openrouter/x-ai/grok-code-fast-1) <aider@aider.chat>
pull/1/head
borja 2 months ago
parent 0c0e0f2da4
commit 9f339ad218

@ -3,7 +3,7 @@ import { db } from '../db';
const env = process.env;
// In-memory cache for active groups
const activeGroupsCache = new Map<string, string>(); // groupId -> groupName
// const activeGroupsCache = new Map<string, string>(); // 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<string, string>(); // 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);
}
}

@ -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)");

Loading…
Cancel
Save