import { readFileSync } from 'node:fs'; import path from 'node:path'; import { describe, expect, it } from 'vitest'; /** * 验收入库补「存放区域」(开发者 2026-10-13): * 验收(含独立进货)入库存量台账时随批次写 `inventory.storage_zone`, * 与「库存入库」面板同列同口径。区域是**自由文本**、无独立表;不填写 NULL。 * * 设计文档:docs/design/20261013-验收入库补存放区域.md * * 本文件钉住:① 服务层入参与 INSERT 带 storage_zone;② 两端路由都映射入参; * ③ 未传区域的自动/合并调用行为不变(入参可选、默认 NULL)。 */ const readServer = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8'); describe('服务层:验收入库写批次存放区域', () => { const svc = readServer('src/services/inspectionComplianceService.ts'); it('入参新增可选 storage_zone(不填即 NULL,旧调用方不受影响)', () => { expect(svc).toContain('storage_zone?: string | null;'); }); it('入库 INSERT 的列清单含 storage_zone,取值 trim 后空转 NULL', () => { expect(svc).toContain('production_date, storage_zone'); expect(svc).toContain("String(input.storage_zone || '').trim() || null"); }); it('普通验收与独立进货共用同一段 INSERT(一处改动覆盖两者)', () => { // 该 INSERT 上文按 writeStockLedger 分支;independentInbound 复用同一写入 expect(svc).toContain('const writeStockLedger ='); expect(svc).toContain('independentInbound'); }); it('不写空串:空/仅空白 ⇒ null(与库存入库同口径)', () => { expect(svc).toContain("String(input.storage_zone || '').trim() || null"); }); }); describe('两端路由映射 storage_zone', () => { it('Web POST /inspection/submit 透传 body.storage_zone', () => { const web = readServer('src/modules/workflow/routes/inspectionRoutes.ts'); const start = web.indexOf("router.post('/inspection/submit'"); const end = web.indexOf("router.get('/processing/tasks'"); const submit = web.slice(start, end); expect(submit).toContain('storage_zone: req.body?.storage_zone'); }); it('移动 POST /mobile/inspection/complete 透传 body.storage_zone', () => { const mobile = readServer('src/routes/mobile/mobileWarehouseRoutes.ts'); const start = mobile.indexOf("router.post('/inspection/complete'"); const end = mobile.indexOf("router.get('/inspection/weigh-station/pending'"); const complete = mobile.slice(start, end); expect(complete).toContain('storage_zone: req.body?.storage_zone'); }); }); describe('验收列表带「上次入库区域」(默认值来源)', () => { it('移动 /inspection/tasks 查询拼上 LAST_INBOUND_ZONE 片段', () => { const mobile = readServer('src/routes/mobile/mobileWarehouseRoutes.ts'); const start = mobile.indexOf("router.get('/inspection/tasks'"); const end = mobile.indexOf("router.post('/inspection/complete'"); const tasks = mobile.slice(start, end); expect(tasks).toContain('LAST_INBOUND_ZONE_SELECT'); expect(tasks).toContain('LAST_INBOUND_ZONE_JOIN'); }); it('Web 列表分页拼上 LAST_INBOUND_ZONE 片段(计数/统计不拼)', () => { const svc = readServer('src/services/inspectionQueryService.ts'); expect(svc).toContain('LAST_INBOUND_ZONE_SELECT'); expect(svc).toContain('listFromSql'); // 统计/计数仍用不带 last_zone 的 fromSql expect(svc).toMatch(/statsRes = await pool\.query\([\s\S]*?\$\{fromSql\}/); }); });