From 7b9f9f2478727ed612c2c44e0d668a2a9a28ac85 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sat, 29 Mar 2025 22:21:56 +0100 Subject: [PATCH] fix: correct test import paths and improve mocks --- tests/unit/services/group-sync.test.ts | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index ad145eb..20fb62f 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -1,7 +1,7 @@ import { describe, it, expect, beforeEach, mock, spyOn } from 'bun:test'; -import { GroupSyncService } from '../../src/services/group-sync'; -import { db } from '../../src/db'; -import { env } from '../../src/env'; +import { GroupSyncService } from '../../../src/services/group-sync'; +import { db } from '../../../src/db'; +import { env } from '../../../src/env'; // Mock the environment variables const originalEnv = { ...env }; @@ -13,16 +13,14 @@ const mockEnv = { }; // Mock fetch -const mockFetch = mock.global('fetch', () => { - return Promise.resolve({ - ok: true, - json: () => Promise.resolve([ - { id: 'group1', subject: 'Group 1', linkedParent: 'test-community' }, - { id: 'group2', subject: 'Group 2', linkedParent: 'other-community' }, - { id: 'group3', subject: 'Group 3' } // No linkedParent - ]) - }); -}); +const mockFetch = mock.global('fetch', async () => ({ + ok: true, + json: async () => [ + { id: 'group1', subject: 'Group 1', linkedParent: 'test-community' }, + { id: 'group2', subject: 'Group 2', linkedParent: 'other-community' }, + { id: 'group3', subject: 'Group 3' } // No linkedParent + ] +})); describe('GroupSyncService', () => { beforeEach(() => { @@ -33,6 +31,7 @@ describe('GroupSyncService', () => { afterAll(() => { Object.assign(env, originalEnv); + mockFetch.mockRestore(); }); describe('syncGroups', () => {