From 89c4b278976f61ad5442deed7992a9c818649353 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sat, 29 Mar 2025 23:52:33 +0100 Subject: [PATCH] test: fix group sync test by mocking console.error --- tests/unit/services/group-sync.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index c0a93bf..539f9e8 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -4,6 +4,7 @@ import { db } from '../../../src/db'; // Store original globals const originalFetch = globalThis.fetch; +const originalConsoleError = console.error; describe('GroupSyncService', () => { let fetchMock: any; @@ -46,8 +47,21 @@ describe('GroupSyncService', () => { }); it('should throw if WHATSAPP_COMMUNITY_ID is missing', async () => { + const consoleErrorMock = mock(() => {}); + console.error = consoleErrorMock; + process.env.WHATSAPP_COMMUNITY_ID = ''; - await expect(GroupSyncService.syncGroups()).rejects.toThrow('WHATSAPP_COMMUNITY_ID is not set'); + + await expect(GroupSyncService.syncGroups()) + .rejects.toThrow('WHATSAPP_COMMUNITY_ID is not set'); + + expect(consoleErrorMock).toHaveBeenCalledWith( + 'Group sync failed:', + expect.any(Error) + ); + + // Restore original console.error + console.error = originalConsoleError; }); it('should filter groups by community ID', async () => {