Files
SupplierSystem/server/tests/weighInspectionMergeSimilar.test.ts
T
Ubuntu deb3e72750
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
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

166 lines
5.4 KiB
TypeScript

import { readFileSync } from 'node:fs';
import path from 'path';
import { describe, expect, it } from 'vitest';
describe('验收称同商品合并入库 + 相近列内选', () => {
it('设计文档存在', () => {
const design = readFileSync(
path.join(__dirname, '../../docs/design/20260910-weigh-inspection-merge-similar-inline.md'),
'utf8'
);
expect(design).toContain('选中行优先');
expect(design).toContain('sp_product');
});
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');
});
});