fix: correct test import paths and improve mocks

main
borja (aider) 3 months ago
parent 3be7783aa8
commit 7b9f9f2478

@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach, mock, spyOn } from 'bun:test'; import { describe, it, expect, beforeEach, mock, spyOn } from 'bun:test';
import { GroupSyncService } from '../../src/services/group-sync'; import { GroupSyncService } from '../../../src/services/group-sync';
import { db } from '../../src/db'; import { db } from '../../../src/db';
import { env } from '../../src/env'; import { env } from '../../../src/env';
// Mock the environment variables // Mock the environment variables
const originalEnv = { ...env }; const originalEnv = { ...env };
@ -13,16 +13,14 @@ const mockEnv = {
}; };
// Mock fetch // Mock fetch
const mockFetch = mock.global('fetch', () => { const mockFetch = mock.global('fetch', async () => ({
return Promise.resolve({ ok: true,
ok: true, json: async () => [
json: () => Promise.resolve([ { id: 'group1', subject: 'Group 1', linkedParent: 'test-community' },
{ id: 'group1', subject: 'Group 1', linkedParent: 'test-community' }, { id: 'group2', subject: 'Group 2', linkedParent: 'other-community' },
{ id: 'group2', subject: 'Group 2', linkedParent: 'other-community' }, { id: 'group3', subject: 'Group 3' } // No linkedParent
{ id: 'group3', subject: 'Group 3' } // No linkedParent ]
]) }));
});
});
describe('GroupSyncService', () => { describe('GroupSyncService', () => {
beforeEach(() => { beforeEach(() => {
@ -33,6 +31,7 @@ describe('GroupSyncService', () => {
afterAll(() => { afterAll(() => {
Object.assign(env, originalEnv); Object.assign(env, originalEnv);
mockFetch.mockRestore();
}); });
describe('syncGroups', () => { describe('syncGroups', () => {

Loading…
Cancel
Save