From 7cef5448c402f89eb4c297f5e1e270c36108c9c6 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sat, 29 Mar 2025 22:23:39 +0100 Subject: [PATCH] fix: correct import paths and env mocking in group-sync tests --- tests/unit/services/group-sync.test.ts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index ae5ab2f..be50da7 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -1,22 +1,15 @@ import { describe, it, expect, beforeEach, mock, spyOn } from 'bun:test'; -import { GroupSyncService } from '../../src/services/group-sync'; -import { db } from '../../src/db'; +import { GroupSyncService } from '../../../src/services/group-sync'; +import { db } from '../../../src/db'; -// Mock environment variables directly since we can't find env.ts -const env = { - WHATSAPP_COMMUNITY_ID: 'test-community', - EVOLUTION_API_URL: 'http://test-api', - EVOLUTION_API_INSTANCE: 'test-instance', - EVOLUTION_API_KEY: 'test-key' -}; - -// Mock the environment variables -const originalEnv = { ...env }; -const mockEnv = { +// Mock process.env for testing +const originalEnv = { ...process.env }; +process.env = { WHATSAPP_COMMUNITY_ID: 'test-community', EVOLUTION_API_URL: 'http://test-api', EVOLUTION_API_INSTANCE: 'test-instance', - EVOLUTION_API_KEY: 'test-key' + EVOLUTION_API_KEY: 'test-key', + ...process.env }; // Mock fetch @@ -37,7 +30,7 @@ describe('GroupSyncService', () => { }); afterAll(() => { - Object.assign(env, originalEnv); + process.env = originalEnv; mockFetch.mockRestore(); });