|
|
@ -52,12 +52,21 @@ describe('GroupSyncService', () => {
|
|
|
|
|
|
|
|
|
|
|
|
it('should filter groups by community ID', async () => {
|
|
|
|
it('should filter groups by community ID', async () => {
|
|
|
|
const result = await GroupSyncService.syncGroups();
|
|
|
|
const result = await GroupSyncService.syncGroups();
|
|
|
|
expect(result.added).toBe(1);
|
|
|
|
expect(result).toEqual({
|
|
|
|
expect(result.updated).toBe(0);
|
|
|
|
added: 1,
|
|
|
|
|
|
|
|
updated: 0
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const groups = db.query('SELECT * FROM groups').all();
|
|
|
|
const groups = db.query('SELECT * FROM groups').all();
|
|
|
|
expect(groups).toHaveLength(1);
|
|
|
|
expect(groups).toEqual([
|
|
|
|
expect(groups[0].id).toBe('group1');
|
|
|
|
{
|
|
|
|
|
|
|
|
id: 'group1',
|
|
|
|
|
|
|
|
community_id: 'test-community',
|
|
|
|
|
|
|
|
name: 'Group 1',
|
|
|
|
|
|
|
|
active: 1,
|
|
|
|
|
|
|
|
last_verified: expect.any(String)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should update existing groups', async () => {
|
|
|
|
it('should update existing groups', async () => {
|
|
|
@ -67,23 +76,37 @@ describe('GroupSyncService', () => {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const result = await GroupSyncService.syncGroups();
|
|
|
|
const result = await GroupSyncService.syncGroups();
|
|
|
|
expect(result.added).toBe(0);
|
|
|
|
expect(result).toEqual({
|
|
|
|
expect(result.updated).toBe(1);
|
|
|
|
added: 0,
|
|
|
|
|
|
|
|
updated: 1
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const group = db.query('SELECT * FROM groups WHERE id = ?').get('group1');
|
|
|
|
const group = db.query('SELECT * FROM groups WHERE id = ?').get('group1');
|
|
|
|
expect(group.name).toBe('Group 1');
|
|
|
|
expect(group).toEqual({
|
|
|
|
expect(group.active).toBe(1);
|
|
|
|
id: 'group1',
|
|
|
|
|
|
|
|
community_id: 'test-community',
|
|
|
|
|
|
|
|
name: 'Group 1',
|
|
|
|
|
|
|
|
active: 1,
|
|
|
|
|
|
|
|
last_verified: expect.any(String)
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should mark non-matching groups as inactive', async () => {
|
|
|
|
it('should mark non-matching groups as inactive', async () => {
|
|
|
|
// Add initial group not in current sync
|
|
|
|
// Add initial group not in current sync
|
|
|
|
db.exec(
|
|
|
|
db.exec(
|
|
|
|
"INSERT INTO groups (id, community_id, name, active) VALUES ('old-group', 'test-community', 'Old Group', 1)"
|
|
|
|
"INSERT INTO groups (id, community_id, name, active, last_verified) VALUES ('old-group', 'test-community', 'Old Group', 1, '2023-01-01')"
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await GroupSyncService.syncGroups();
|
|
|
|
await GroupSyncService.syncGroups();
|
|
|
|
const group = db.query('SELECT active FROM groups WHERE id = ?').get('old-group');
|
|
|
|
const group = db.query('SELECT * FROM groups WHERE id = ?').get('old-group');
|
|
|
|
expect(group.active).toBe(0);
|
|
|
|
expect(group).toEqual({
|
|
|
|
|
|
|
|
id: 'old-group',
|
|
|
|
|
|
|
|
community_id: 'test-community',
|
|
|
|
|
|
|
|
name: 'Old Group',
|
|
|
|
|
|
|
|
active: 0,
|
|
|
|
|
|
|
|
last_verified: expect.any(String)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(group.last_verified).not.toBe('2023-01-01'); // Should be updated
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should handle API errors', async () => {
|
|
|
|
it('should handle API errors', async () => {
|
|
|
|