fix(attendance): 默认周范围改为中国日期周一起点
generateFromSchedules / getCalendar 原来用本地周一零点转 UTC 日期, 在上海时区会得到前一天的日期,导致默认范围变成周日~周日(8 天)。 改为 dayjs().utcOffset(8) 按中国日期计算,与 getTodayDateOnly 语义一致。 新增测试锁定:默认周 = 本周一~本周日,周日晚上仍归本周,显式传参原样透传。
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { AttendanceCalendarService } from './attendance-calendar.service';
|
||||
|
||||
describe('AttendanceCalendarService — 默认周起点', () => {
|
||||
function createService() {
|
||||
return new AttendanceCalendarService({} as never, {} as never);
|
||||
}
|
||||
|
||||
afterEach(() => jest.useRealTimers());
|
||||
|
||||
it('未传 weekStart 时默认本周一(中国日期)', async () => {
|
||||
jest.useFakeTimers().setSystemTime(new Date('2026-08-05T10:00:00+08:00')); // 周三
|
||||
const service = createService();
|
||||
const spy = jest
|
||||
.spyOn(service as never, 'buildCalendar' as never)
|
||||
.mockResolvedValue([] as never);
|
||||
|
||||
await service.getCalendar({ classId: 1 } as never);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(1, '2026-08-03');
|
||||
});
|
||||
|
||||
it('周日晚间仍归入本周一', async () => {
|
||||
jest.useFakeTimers().setSystemTime(new Date('2026-08-09T22:00:00+08:00')); // 周日晚上
|
||||
const service = createService();
|
||||
const spy = jest
|
||||
.spyOn(service as never, 'buildCalendar' as never)
|
||||
.mockResolvedValue([] as never);
|
||||
|
||||
await service.getCalendar({ classId: 1 } as never);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(1, '2026-08-03');
|
||||
});
|
||||
|
||||
it('传入 weekStart 时原样透传', async () => {
|
||||
const service = createService();
|
||||
const spy = jest
|
||||
.spyOn(service as never, 'buildCalendar' as never)
|
||||
.mockResolvedValue([] as never);
|
||||
|
||||
await service.getCalendar({ classId: 1, weekStart: '2026-08-10' } as never);
|
||||
|
||||
expect(spy).toHaveBeenCalledWith(1, '2026-08-10');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user