Files
SupplierSystem/server/tests/weighInspectionMergeSimilar.test.ts
Ubuntu 5fa2bbfd55
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
fix(audit-20261019): T1-T9 审计修复、存储归属与审计日志列宽
- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14)
- T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9)
- T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4)
- T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8)
- T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15)
- T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8)
- T7 前后端测试与 lint 门禁清零
- T8 应付卡片按关联订单日(口径 A)
- T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
2026-10-19 16:16:51 +08:00

160 lines
5.5 KiB
TypeScript

import { readFileSync } from 'node:fs';
import path from 'path';
import { describe, expect, it } from 'vitest';
describe('验收称同商品合并入库 + 相近列内选', () => {
// 原「设计文档存在」断言已移除:`20260910-weigh-inspection-merge-similar-inline.md`
// 不在本仓库(git 历史亦无此文件;合并口径现由 `20260910-weigh-merge-total-batch.md` 覆盖)。
// 行为契约由本文件其余用例与 `weighInspectionMergeSimilar` 服务用例覆盖(T7 AC-T7.1.3)。
it('总重量分批抵扣设计存在', () => {
const design = readFileSync(
path.join(__dirname, '../../docs/design/20260910-weigh-merge-total-batch.md'),
'utf8'
);
expect(design).toContain('分批');
expect(design).toContain('need_confirm_over');
});
it('服务端导出 merge 并挂路由', () => {
const weigh = readFileSync(
path.join(__dirname, '../src/services/weighStationService.ts'),
'utf8'
);
expect(weigh).toContain('submitInspectionWeighMergeByProduct');
expect(weigh).toContain('orderMergeInspectionLines');
expect(weigh).toContain('allocateMergeInspectionQtys');
expect(weigh).toContain('mergedCount');
// 2026-09-17 起超量不再拦截:原 400 need_confirm_over 已移除,改为一律照实入账 + 留痕
// 见 docs/design/20260917-weigh-over-qty-confirm.md
expect(weigh).toContain('confirmOverQty: true');
expect(weigh).not.toContain("code: 'need_confirm_over'");
const routes = readFileSync(
path.join(__dirname, '../src/routes/mobile/mobileWarehouseRoutes.ts'),
'utf8'
);
expect(routes).toContain('/inspection/complete-merge');
expect(routes).toContain('submitInspectionWeighMergeByProduct');
});
it('选中行优先于 created_at FIFO', async () => {
const { orderMergeInspectionLines } = await import('../src/services/weighStationService');
const ordered = orderMergeInspectionLines(
[
{ id: 'old', prepare_qty: 10 },
{ id: 'new', prepare_qty: 10 },
],
'new'
);
expect(ordered.map((r) => r.id)).toEqual(['new', 'old']);
});
it('总重量分批抵扣:够合计全结、不够分摊、超量未确认保留 unallocated', async () => {
const { allocateMergeInspectionQtys, orderMergeInspectionLines } = await import(
'../src/services/weighStationService'
);
const lines = orderMergeInspectionLines(
[
{ id: 'a', prepare_qty: 10 },
{ id: 'b', prepare_qty: 10 },
],
'a'
);
const full = allocateMergeInspectionQtys(lines, 20);
expect(full.allocations).toEqual([
{ id: 'a', qty: 10 },
{ id: 'b', qty: 10 },
]);
expect(full.unallocated).toBe(0);
const batch = allocateMergeInspectionQtys(lines, 12);
expect(batch.allocations).toEqual([
{ id: 'a', qty: 10 },
{ id: 'b', qty: 2 },
]);
expect(batch.unallocated).toBe(0);
const over = allocateMergeInspectionQtys(lines, 25);
expect(over.allocations).toEqual([
{ id: 'a', qty: 10 },
{ id: 'b', qty: 10 },
]);
expect(over.unallocated).toBeCloseTo(5);
const overOk = allocateMergeInspectionQtys(lines, 25, { confirmOverQty: true });
expect(overOk.allocations).toEqual([
{ id: 'a', qty: 10 },
{ id: 'b', qty: 15 },
]);
expect(overOk.unallocated).toBe(0);
});
it('Android:列内选相近 + completeMerge + 需 SUM + 分批提示', () => {
const act = readFileSync(
path.join(
__dirname,
'../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/ui/InspectionWeighActivity.java'
),
'utf8'
);
expect(act).toContain('formatSimilarCandidateLabel');
expect(act).toContain(' · 需');
expect(act).toContain('rebuildSimilarPickLabelsFromDemand');
expect(act).toContain('applySimilarCandidate');
expect(act).toContain('默认最像');
expect(act).not.toContain('showSimilarCandidatesPickDialog');
expect(act).toContain('completeMerge');
expect(act).toContain('prevReq + remain');
expect(act).toContain('已分批抵扣');
const api = readFileSync(
path.join(
__dirname,
'../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/api/InspectionApi.java'
),
'utf8'
);
expect(api).toContain('complete-merge');
expect(api).toContain('force_complete');
});
it('Android:偏差入库按钮 + forceComplete', () => {
const act = readFileSync(
path.join(
__dirname,
'../../android-weigh-terminal/app/src/main/java/com/canteen/weigh/ui/InspectionWeighActivity.java'
),
'utf8'
);
expect(act).toContain('btn_force_complete');
expect(act).toContain('confirmSubmit(true)');
expect(act).toContain('forceComplete');
expect(act).toContain('偏差入库');
const layout = readFileSync(
path.join(
__dirname,
'../../android-weigh-terminal/app/src/main/res/layout/activity_inspection_weigh.xml'
),
'utf8'
);
expect(layout).toContain('偏差入库');
expect(layout).toContain('确认入库');
const weigh = readFileSync(
path.join(__dirname, '../src/services/weighStationService.ts'),
'utf8'
);
expect(weigh).toContain('force_complete');
expect(weigh).toContain('forceComplete');
const compliance = readFileSync(
path.join(__dirname, '../src/services/inspectionComplianceService.ts'),
'utf8'
);
expect(compliance).toContain('force_complete');
expect(compliance).toContain('forceComplete');
});
});