forked from wangziqi/gongxue-base
test: harden business boundary conditions
This commit is contained in:
@@ -549,3 +549,63 @@ describe('ScheduleSyncService — multiple lessons per student per day', () => {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('ScheduleSyncService — date and overnight boundaries', () => {
|
||||
const createService = (schedule: ClassSchedule) => {
|
||||
const scheduleUsers = jest.fn().mockResolvedValue(undefined);
|
||||
const upsertShift = jest.fn().mockResolvedValue(501);
|
||||
const service = new ScheduleSyncService(
|
||||
{ find: jest.fn().mockResolvedValue([schedule]) } as never,
|
||||
{ find: jest.fn().mockResolvedValue([{ classId: 10, studentId: 20, status: 'active' }]) } as never,
|
||||
{ find: jest.fn().mockResolvedValue([{ studentId: 20, dingUserId: 'student-1' }]) } as never,
|
||||
{ find: jest.fn().mockResolvedValue([{ id: 10, name: '边界班' }]) } as never,
|
||||
{
|
||||
queryShifts: jest.fn().mockResolvedValue([]), upsertShift,
|
||||
queryAttendanceGroups: jest.fn().mockResolvedValue([
|
||||
{ group_id: 88, group_name: '排课_边界班', type: 'TURN', member_count: 1 },
|
||||
]),
|
||||
updateAttendanceGroup: jest.fn().mockResolvedValue(undefined),
|
||||
createAttendanceGroup: jest.fn(), scheduleUsers,
|
||||
} as never,
|
||||
);
|
||||
return { service, scheduleUsers, upsertShift };
|
||||
};
|
||||
|
||||
it('syncs exactly the requested number of calendar days', async () => {
|
||||
const { service, scheduleUsers } = createService({
|
||||
id: 1, classId: 10, weekDay: 1, startTime: '09:00', endTime: '10:00',
|
||||
startDate: '2026-07-13', endDate: '2026-07-20', status: 'active',
|
||||
} as ClassSchedule);
|
||||
await service.syncAll('2026-07-13', 7);
|
||||
expect(scheduleUsers.mock.calls.flatMap((call) => call[1])).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('marks an overnight lesson off-duty time as next-day', async () => {
|
||||
const { service, upsertShift } = createService({
|
||||
id: 1, classId: 10, weekDay: 1, startTime: '22:00', endTime: '01:00',
|
||||
startDate: '2026-07-13', endDate: '2026-07-13', status: 'active',
|
||||
} as ClassSchedule);
|
||||
await service.syncAll('2026-07-13', 1);
|
||||
expect(upsertShift).toHaveBeenCalledWith(expect.objectContaining({
|
||||
sections: [expect.objectContaining({ times: expect.arrayContaining([
|
||||
expect.objectContaining({ check_type: 'OnDuty', across: 0 }),
|
||||
expect.objectContaining({ check_type: 'OffDuty', across: 1 }),
|
||||
]) })],
|
||||
}));
|
||||
});
|
||||
|
||||
it('does not shift the requested date when the server timezone is behind China', async () => {
|
||||
const originalTz = process.env.TZ;
|
||||
process.env.TZ = 'America/Los_Angeles';
|
||||
try {
|
||||
const { service, scheduleUsers } = createService({
|
||||
id: 1, classId: 10, weekDay: 1, startTime: '09:00', endTime: '10:00',
|
||||
startDate: '2026-07-13', endDate: '2026-07-13', status: 'active',
|
||||
} as ClassSchedule);
|
||||
await service.syncAll('2026-07-13', 1);
|
||||
expect(scheduleUsers).toHaveBeenCalledTimes(1);
|
||||
} finally {
|
||||
process.env.TZ = originalTz;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user