test: fix group sync test by mocking console.error

main
borja (aider) 3 months ago
parent 1d29fedc18
commit 89c4b27897

@ -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 () => {

Loading…
Cancel
Save