From 43bd5080eaa368e6fa4b2d4d598c0f5669ce306d Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sun, 30 Mar 2025 16:39:54 +0200 Subject: [PATCH] fix: update group sync tests to use proper Response mocks --- tests/unit/services/group-sync.test.ts | 34 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index 0c3cbaf..2436719 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -15,18 +15,22 @@ describe('GroupSyncService', () => { db.exec('DELETE FROM sqlite_sequence WHERE name="groups"'); GroupSyncService['lastSyncAttempt'] = 0; - // Setup mock fetch - fetchMock = mock(async () => ({ - ok: true, - json: async () => ({ - status: 'success', - response: [ - { id: 'group1', subject: 'Group 1', linkedParent: 'test-community' }, - { id: 'group2', subject: 'Group 2', linkedParent: 'other-community' }, - { id: 'group3', subject: 'Group 3' } // No linkedParent - ] - }) - })); + // Setup mock fetch to return proper Response object + fetchMock = mock(async () => { + const groups = [ + { id: 'group1', subject: 'Group 1', linkedParent: 'test-community' }, + { id: 'group2', subject: 'Group 2', linkedParent: 'other-community' }, + { id: 'group3', subject: 'Group 3' } // No linkedParent + ]; + return { + ok: true, + status: 200, + statusText: 'OK', + headers: new Headers({'Content-Type': 'application/json'}), + text: async () => JSON.stringify(groups), + json: async () => groups + }; + }); globalThis.fetch = fetchMock; // Setup env vars @@ -139,7 +143,11 @@ describe('GroupSyncService', () => { globalThis.fetch = mock(async () => ({ ok: false, - statusText: 'Not Found' + status: 404, + statusText: 'Not Found', + headers: new Headers(), + text: async () => 'Not Found', + json: async () => ({ error: 'Not Found' }) })); await expect(GroupSyncService.syncGroups()).rejects.toThrow('API request failed: Not Found');