From df6d9926af05bb3907c1586d9357154f44f36dcd Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Sat, 29 Mar 2025 23:54:06 +0100 Subject: [PATCH] test: fix group sync test by resetting lastSyncAttempt and improving assertions --- tests/unit/services/group-sync.test.ts | 30 ++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/tests/unit/services/group-sync.test.ts b/tests/unit/services/group-sync.test.ts index 539f9e8..3fdb8a9 100644 --- a/tests/unit/services/group-sync.test.ts +++ b/tests/unit/services/group-sync.test.ts @@ -65,22 +65,30 @@ describe('GroupSyncService', () => { }); it('should filter groups by community ID', async () => { + // Reset last sync attempt to force a sync + GroupSyncService['lastSyncAttempt'] = 0; + const result = await GroupSyncService.syncGroups(); + + // Verify the correct groups were processed expect(result).toEqual({ - added: 1, - updated: 0 + added: 1, // group1 should be added + updated: 0 // no existing groups to update }); + // Verify database state const groups = db.query('SELECT * FROM groups').all(); - expect(groups).toEqual([ - { - id: 'group1', - community_id: 'test-community', - name: 'Group 1', - active: 1, - last_verified: expect.any(String) - } - ]); + expect(groups).toHaveLength(1); + + const group = groups[0]; + expect(group.id).toBe('group1'); + expect(group.community_id).toBe('test-community'); + expect(group.name).toBe('Group 1'); + expect(group.active).toBe(1); + expect(group.last_verified).toBeTruthy(); + + // Verify only the matching group was processed + expect(fetchMock).toHaveBeenCalledTimes(1); }); it('should update existing groups', async () => {