fix: harden DingTalk student synchronization

This commit is contained in:
2026-07-18 14:51:53 +08:00
parent d25e451b61
commit c11f6bb614
15 changed files with 758 additions and 356 deletions

View File

@@ -1,3 +1,4 @@
import { BadRequestException } from '@nestjs/common';
import { SyncController } from './sync.controller';
import { ScheduleSyncQueryDto } from './dto/schedule-sync.dto';
@@ -20,4 +21,26 @@ describe('SyncController — schedule sync options', () => {
true,
);
});
it.each(['1abc', '0', '-1', '9007199254740992'])(
'rejects invalid root department id %s',
async (rootDeptId) => {
const syncService = { triggerSync: jest.fn() };
const controller = new SyncController(syncService as never);
await expect(controller.triggerSync('dingtalk_students', rootDeptId)).rejects.toBeInstanceOf(
BadRequestException,
);
expect(syncService.triggerSync).not.toHaveBeenCalled();
},
);
it('accepts a positive integer root department id', async () => {
const syncService = { triggerSync: jest.fn().mockResolvedValue([]) };
const controller = new SyncController(syncService as never);
await controller.triggerSync('dingtalk_students', '12');
expect(syncService.triggerSync).toHaveBeenCalledWith('dingtalk_students', 12);
});
});