You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			TypeScript
		
	
| import { describe, test, expect, beforeEach, afterEach } from 'bun:test';
 | |
| import { GroupSyncService } from '../../../src/services/group-sync';
 | |
| 
 | |
| const envBackup = { ...process.env };
 | |
| let originalSyncMembers: any;
 | |
| 
 | |
| function sleep(ms: number) {
 | |
|   return new Promise(res => setTimeout(res, ms));
 | |
| }
 | |
| 
 | |
| describe('GroupSyncService - scheduler de miembros', () => {
 | |
|   beforeEach(() => {
 | |
|     originalSyncMembers = GroupSyncService.syncMembersForActiveGroups;
 | |
|   });
 | |
| 
 | |
|   afterEach(() => {
 | |
|     GroupSyncService.stopMembersScheduler();
 | |
|     GroupSyncService.syncMembersForActiveGroups = originalSyncMembers;
 | |
|     process.env = envBackup;
 | |
|   });
 | |
| 
 | |
|   test('no arranca en entorno de test', async () => {
 | |
|     process.env = { ...envBackup, NODE_ENV: 'test' };
 | |
|     let called = 0;
 | |
|     GroupSyncService.syncMembersForActiveGroups = async () => {
 | |
|       called++;
 | |
|       return { groups: 0, added: 0, updated: 0, deactivated: 0 };
 | |
|     };
 | |
| 
 | |
|     GroupSyncService.startMembersScheduler();
 | |
|     await sleep(100);
 | |
|     expect(called).toBe(0);
 | |
|   });
 | |
| 
 | |
|   test('arranca en producción y ejecuta según intervalo', async () => {
 | |
|     process.env = { ...envBackup, NODE_ENV: 'production', GROUP_MEMBERS_SYNC_INTERVAL_MS: '30' };
 | |
|     let called = 0;
 | |
|     GroupSyncService.syncMembersForActiveGroups = async () => {
 | |
|       called++;
 | |
|       return { groups: 0, added: 0, updated: 0, deactivated: 0 };
 | |
|     };
 | |
| 
 | |
|     GroupSyncService.startMembersScheduler();
 | |
|     await sleep(120);
 | |
|     GroupSyncService.stopMembersScheduler();
 | |
|     expect(called).toBeGreaterThanOrEqual(1);
 | |
|   });
 | |
| });
 |