Files
gongxue-base/apps/server/src/occupancies/occupancy-import-template.spec.ts
wangziqi c7ba2799b9 feat: 拆分学号/身份证字段 + 考勤教师展示 + 代码优化
- 入住导入模板:学号和身份证号拆为独立字段,前后端对齐
- 排课查询关联教师,考勤归档页展示教师姓名
- 抽查时段增加 IsIn 校验
- 抽取 withPessimisticWriteLock 去重悲观锁查询
- import 增加文件空 buffer 校验
- 测试 mock 补全,适配事务 manager
- MySQL init.sql VALUES() 语法兼容修复
2026-07-20 11:54:01 +08:00

84 lines
2.9 KiB
TypeScript

import {
createOccupancyImportTemplateWorkbook,
OCCUPANCY_IMPORT_COLUMNS,
parseOccupancyImportWorksheet,
} from './occupancy-import-template';
describe('occupancy import template', () => {
it('includes the current occupancy fields including separate student and ID numbers', () => {
const workbook = createOccupancyImportTemplateWorkbook();
const ws = workbook.getWorksheet('入住名单导入模板')!;
const headers = ws.getRow(1).values as unknown[];
expect(headers).toEqual(
expect.arrayContaining([
'宿舍号',
'楼栋',
'床位号',
'柜子号',
'计费起始日',
'电话',
'学号',
'身份证号',
'入住类型',
'备注',
]),
);
expect(headers).not.toContain('所属机构');
expect(headers).not.toContain('学号/身份证');
expect(ws.columnCount).toBe(OCCUPANCY_IMPORT_COLUMNS.length);
});
it('documents the current phone matching, organization, and deposit behavior', () => {
const workbook = createOccupancyImportTemplateWorkbook();
const helpWs = workbook.getWorksheet('使用说明')!;
const instructions = helpWs.getColumn(1).values.join('\n');
expect(instructions).toContain('按手机号关联已有学生');
expect(instructions).toContain('学号和身份证号为两个独立字段');
expect(instructions).toContain('所属机构自动取学生档案');
expect(instructions).toContain('导入时自动收押金');
expect(instructions).toContain('历史入住不会自动收取');
});
it('keeps Excel Date cells on the same local calendar day', () => {
const workbook = createOccupancyImportTemplateWorkbook();
const ws = workbook.getWorksheet('入住名单导入模板')!;
ws.getCell('K2').value = new Date(2026, 3, 21);
ws.getCell('L2').value = new Date(2026, 3, 22);
ws.getCell('M2').value = new Date(2026, 3, 30);
expect(parseOccupancyImportWorksheet(ws)[0]).toMatchObject({
checkInDate: '2026-04-21',
billingStartDate: '2026-04-22',
checkOutDate: '2026-04-30',
});
});
it('parses rows by header so new columns do not shift existing fields', () => {
const workbook = createOccupancyImportTemplateWorkbook();
const ws = workbook.getWorksheet('入住名单导入模板')!;
const rows = parseOccupancyImportWorksheet(ws);
expect(rows[0]).toMatchObject({
roomNumber: '4-102',
building: '4号楼',
bedNumber: '1号床',
lockerNumber: 'A01',
name: '张三',
studentNo: '2024001',
idNumber: '11010120060101001X',
checkInDate: '2026-04-21',
billingStartDate: '2026-04-21',
stayType: 'short',
});
expect(rows[1]).toMatchObject({
bedNumber: '2号床',
lockerNumber: 'A02',
studentNo: '2024002',
idNumber: '11010120060202002X',
stayType: 'long',
});
});
});