Files
SupplierSystem/server/tests/mainSystemImportPrepDedupe.test.ts
T
Ubuntu e481da6852
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(主系统导入): 同一 prep_id 一轮只追加一次(修重复行)
真机(本地):清理"陈旧台账指针"把行级对照清空后,同一 prep_id 被当成新行追加两遍,
本地日单出现 4 组重复行(好人家蒸肉粉/干胡豆瓣/干豆腐皮/测试商品 各 2 行)。

修复:collectNewRowsForBucket 内按 prep_id(row.id)去重——建单与追加两条路都经过它;
按业务行去重,不按商品名/数量(同名不同行必须都保留)。

验证:npx tsc --noEmit 0 错;新增 mainSystemImportPrepDedupe 2 条;
mainSystem 子集 32 文件 / 484 用例全过。
2026-10-18 01:24:09 +08:00

32 lines
1.3 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';
/**
* 同一主系统备货行(`prep_id`)在一轮导入里只允许追加一次。
*
* 真机(2026-10-17):清理"陈旧台账指针"把行级对照清空后,同一 `prep_id` 被当成新行追加了两次,
* 本地日单出现 4 组重复行(好人家蒸肉粉/干胡豆瓣/干豆腐皮/测试商品 各 2 行)。
*/
const service = readFileSync(
path.join(__dirname, '../src/services/mainSystemOrderImport.ts'),
'utf8'
);
describe('导入去重:同一 prep_id 一轮只追加一次', () => {
const idx = service.indexOf('function collectNewRowsForBucket(');
const block = idx >= 0 ? service.slice(idx, idx + 1600) : '';
it('collectNewRowsForBucket 内按 prep_id 去重(建单/追加两条路都经过它)', () => {
expect(idx).toBeGreaterThan(-1);
expect(block).toMatch(/seenPrepIds/);
expect(block).toMatch(/seenPrepIds\.has\(prepId\)\) return false/);
expect(block).toMatch(/seenPrepIds\.add\(prepId\)/);
});
it('去重按 prep_id(row.id),不是按商品名/数量(同名不同行必须都保留)', () => {
expect(block).toMatch(/const prepId = String\(row\.id/);
expect(block).not.toMatch(/itemName\)\) return false/);
});
});