来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
82 lines
3.2 KiB
TypeScript
82 lines
3.2 KiB
TypeScript
import { readFileSync } from 'fs';
|
|
import path from 'path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { allocateMergeInspectionQtys } from '../src/services/weighStationService';
|
|
|
|
/**
|
|
* 称端合并入库:超量(实收 > 同商品合计待入)不再是无解死路。
|
|
* 背景与实测见 docs/design/20260917-weigh-over-qty-confirm.md
|
|
*/
|
|
|
|
const readSource = (rel: string) => readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
|
|
describe('allocateMergeInspectionQtys:超量归属', () => {
|
|
const lines = [
|
|
{ id: 'a', prepare_qty: 10 },
|
|
{ id: 'b', prepare_qty: 10 },
|
|
];
|
|
|
|
it('未确认超量时:只按各行 prepare 分配,余量留在 unallocated', () => {
|
|
const r = allocateMergeInspectionQtys(lines, 30, { confirmOverQty: false });
|
|
expect(r.sumPrepare).toBe(20);
|
|
expect(r.allocations).toEqual([
|
|
{ id: 'a', qty: 10 },
|
|
{ id: 'b', qty: 10 },
|
|
]);
|
|
expect(r.unallocated).toBe(10);
|
|
});
|
|
|
|
it('已确认超量时:余量记到最后一行,unallocated 归零', () => {
|
|
const r = allocateMergeInspectionQtys(lines, 30, { confirmOverQty: true });
|
|
expect(r.allocations).toEqual([
|
|
{ id: 'a', qty: 10 },
|
|
{ id: 'b', qty: 20 },
|
|
]);
|
|
expect(r.unallocated).toBe(0);
|
|
});
|
|
|
|
it('合并层固定按「已确认」调用:任何入参都不会留下 unallocated', () => {
|
|
// 服务端已不再把 confirmOverQty 绑定到入参(源码契约见下),这里锁住纯函数语义
|
|
const r = allocateMergeInspectionQtys(lines, 30, { confirmOverQty: true });
|
|
expect(r.unallocated).toBe(0);
|
|
expect(r.allocations.reduce((s, x) => s + x.qty, 0)).toBe(30);
|
|
});
|
|
|
|
it('实收小于合计待入时行为不变(无溢出)', () => {
|
|
const r = allocateMergeInspectionQtys(lines, 15, { confirmOverQty: false });
|
|
expect(r.allocations).toEqual([{ id: 'a', qty: 10 }, { id: 'b', qty: 5 }]);
|
|
expect(r.unallocated).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe('服务端源码契约:超量一律不拦,照实入账 + 留痕', () => {
|
|
const weigh = readSource('src/services/weighStationService.ts');
|
|
|
|
it('合并层不再有 need_confirm_over 拦截(两个按钮都不拦)', () => {
|
|
expect(weigh).not.toContain("code: 'need_confirm_over'");
|
|
expect(weigh).not.toContain('请确认超量后再入库');
|
|
expect(weigh).toContain('confirmOverQty: true');
|
|
});
|
|
|
|
it('超量必须留痕并可查:最后一行写 over_qty_confirmed / over_qty / 来源', () => {
|
|
for (const key of ['over_qty_confirmed', 'over_qty', 'over_qty_sum_prepare', 'over_qty_confirm_source']) {
|
|
expect(weigh, key).toContain(key);
|
|
}
|
|
expect(weigh).toContain('withOverQtyTrace');
|
|
expect(weigh).toContain('i === allocations.length - 1');
|
|
// 来源要能区分:偏差入库 / 显式传参 / 自动接受
|
|
for (const src of ['force_complete', 'confirm_over_qty', 'auto_accept']) {
|
|
expect(weigh, src).toContain(src);
|
|
}
|
|
});
|
|
|
|
it('承载超量的那一行同时满足过手超量闸门(口径一致,避免半提交)', () => {
|
|
expect(weigh).toContain('carriesOverQty ||');
|
|
});
|
|
|
|
it('响应回传超量事实(称端/审计可见)', () => {
|
|
expect(weigh).toContain('overQty,');
|
|
expect(weigh).toContain('overQtyConfirmed:');
|
|
});
|
|
});
|