Files
SupplierSystem/server/tests/inspectionStorageZone.test.ts
T
雨天 2f439026d3
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
feat(验收): 入库补存放区域,默认取上次区域
Web 验收弹窗与小程序验收面板新增「存放区域」,随批次写入 inventory.storage_zone;独立进货走同一段 INSERT 一并覆盖。

默认值 = 该商品上次入库区域(同 SKU 最近一批非空区域):后端列表接口带 last_storage_zone,只拼在带 LIMIT 的列表查询上,不并入计数类查询。

区域为自由文本、无独立表:Web 复用 /inventory/storage-zones 候选 + 输入即新增;小程序原生 picker + 末尾「+ 新增区域」。不新增前端文案。称重台/Android 不做。

测试:server/tests/inspectionStorageZone.test.ts(8 例)、src/utils/inspectionStorageZone.contract.test.ts(13 例);npm run typecheck 通过;last_zone 片段已对本地库实跑。
2026-10-13 16:26:17 +08:00

77 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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\}/);
});
});