|
|
@ -15,18 +15,22 @@ describe('GroupSyncService', () => {
|
|
|
|
db.exec('DELETE FROM sqlite_sequence WHERE name="groups"');
|
|
|
|
db.exec('DELETE FROM sqlite_sequence WHERE name="groups"');
|
|
|
|
GroupSyncService['lastSyncAttempt'] = 0;
|
|
|
|
GroupSyncService['lastSyncAttempt'] = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Setup mock fetch
|
|
|
|
// Setup mock fetch to return proper Response object
|
|
|
|
fetchMock = mock(async () => ({
|
|
|
|
fetchMock = mock(async () => {
|
|
|
|
ok: true,
|
|
|
|
const groups = [
|
|
|
|
json: async () => ({
|
|
|
|
{ id: 'group1', subject: 'Group 1', linkedParent: 'test-community' },
|
|
|
|
status: 'success',
|
|
|
|
{ id: 'group2', subject: 'Group 2', linkedParent: 'other-community' },
|
|
|
|
response: [
|
|
|
|
{ id: 'group3', subject: 'Group 3' } // No linkedParent
|
|
|
|
{ id: 'group1', subject: 'Group 1', linkedParent: 'test-community' },
|
|
|
|
];
|
|
|
|
{ id: 'group2', subject: 'Group 2', linkedParent: 'other-community' },
|
|
|
|
return {
|
|
|
|
{ id: 'group3', subject: 'Group 3' } // No linkedParent
|
|
|
|
ok: true,
|
|
|
|
]
|
|
|
|
status: 200,
|
|
|
|
})
|
|
|
|
statusText: 'OK',
|
|
|
|
}));
|
|
|
|
headers: new Headers({'Content-Type': 'application/json'}),
|
|
|
|
|
|
|
|
text: async () => JSON.stringify(groups),
|
|
|
|
|
|
|
|
json: async () => groups
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
|
|
|
globalThis.fetch = fetchMock;
|
|
|
|
globalThis.fetch = fetchMock;
|
|
|
|
|
|
|
|
|
|
|
|
// Setup env vars
|
|
|
|
// Setup env vars
|
|
|
@ -139,7 +143,11 @@ describe('GroupSyncService', () => {
|
|
|
|
|
|
|
|
|
|
|
|
globalThis.fetch = mock(async () => ({
|
|
|
|
globalThis.fetch = mock(async () => ({
|
|
|
|
ok: false,
|
|
|
|
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');
|
|
|
|
await expect(GroupSyncService.syncGroups()).rejects.toThrow('API request failed: Not Found');
|
|
|
|