feat: refine deposit room type workflows

This commit is contained in:
2026-07-17 17:36:04 +08:00
parent a5bda6f093
commit b3d0bafc22
11 changed files with 724 additions and 140 deletions

View File

@@ -234,6 +234,106 @@ describe('AttendanceService — DingTalk raw query', () => {
});
describe('AttendanceService — attendance device display mappings', () => {
function createHistoryQueryBuilder(records: AttendanceRecord[]) {
return {
leftJoinAndSelect: jest.fn().mockReturnThis(),
andWhere: jest.fn().mockReturnThis(),
orderBy: jest.fn().mockReturnThis(),
addOrderBy: jest.fn().mockReturnThis(),
skip: jest.fn().mockReturnThis(),
take: jest.fn().mockReturnThis(),
getManyAndCount: jest.fn().mockResolvedValue([records, records.length]),
getMany: jest.fn().mockResolvedValue(records),
};
}
function createServiceWithRecords(records: AttendanceRecord[]) {
const qb = createHistoryQueryBuilder(records);
const attendanceRepo = { createQueryBuilder: jest.fn().mockReturnValue(qb) };
const attendanceDeviceRepo = {
find: jest.fn().mockImplementation(async (options: { where?: Record<string, unknown> }) => {
if (options.where && 'deviceSn' in options.where) {
return [
{
id: 1,
deviceSn: 'ATM-01',
deviceName: '东门考勤机',
classroomId: 8,
classroom: { id: 8, name: '一号教室' },
status: 'disabled',
},
];
}
return [];
}),
};
const service = new AttendanceService(
attendanceRepo as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
{} as never,
attendanceDeviceRepo as never,
{} as never,
);
return { service, qb, attendanceDeviceRepo };
}
it('maps history list punch device ids to configured attendance device names', async () => {
const record = {
id: 1,
classId: 8,
status: 'present',
source: 'dingtalk',
punchSource: 'ATM',
punchDeviceId: 'ATM-01',
punchDeviceName: '钉钉原始设备名',
} as AttendanceRecord;
const { service, attendanceDeviceRepo } = createServiceWithRecords([record]);
await expect(service.findAll({}, [8])).resolves.toMatchObject({
list: [
{
punchDeviceId: 'ATM-01',
punchDeviceName: '东门考勤机 · 一号教室',
},
],
total: 1,
});
expect(attendanceDeviceRepo.find).toHaveBeenCalledWith({
where: { deviceSn: expect.any(Object) },
relations: ['classroom'],
});
});
it('maps exported punch device ids to configured attendance device names', async () => {
const record = {
id: 2,
classId: 8,
status: 'present',
source: 'dingtalk',
punchSource: 'ATM',
punchDeviceId: 'ATM-01',
punchDeviceName: '钉钉原始设备名',
} as AttendanceRecord;
const { service } = createServiceWithRecords([record]);
await expect(service.findAllForExport({}, [8])).resolves.toEqual([
expect.objectContaining({
punchDeviceId: 'ATM-01',
punchDeviceName: '东门考勤机 · 一号教室',
}),
]);
});
});
// ── Session serialization tests ──
function deferred<T>(): {
promise: Promise<T>;