Files
SupplierSystem/src/utils/inboundArchiveBatch.test.ts
T
雨天 1cd4b2c89f 批量入库: 人工改过的规格回写商品档案
inventory 无 spec 列 ⇒「上次入库的规格」唯一落点是商品档案,而批量入库对已匹配老商品从不回写,导致下次选同一商品带不出规格。

按方案 A 扩已批准的「档案回写」:只回写人工改过的字段(AI/预填值绝不覆盖),在入库同事务内写 product_catalog.spec。
- 服务端: StockImportRowInput/BatchInboundRowInput 增 archive,透传到 writeStockImportRow 调 applyArchiveWriteback
- 前端: 行上脏标记(选商品/点候选/新建商品预填即清),只对已匹配且被改过的行发 archive;Web 与小程序两端一致
- 新增 buildBatchRowArchive + 单测/契约测试 + 设计文档
2026-10-16 14:13:34 +08:00

43 lines
1.7 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 { describe, expect, it } from 'vitest';
import { buildBatchRowArchive } from './inboundArchiveBatch';
/**
* 批量入库档案回写载荷(方案 A):只回写**人工改过**的字段。
* 口径见 docs/design/20261016-批量入库规格回写商品档案.md。
* 这些用例守的是**回写边界**:识别值 / 档案预填值不能冒充人工值。
*/
describe('buildBatchRowArchive', () => {
it('无人工编辑 ⇒ null(不传 archive,服务端不写档案)', () => {
expect(buildBatchRowArchive({ spec: '约500g', origin: '内蒙古' }, {})).toBeNull();
expect(buildBatchRowArchive({}, { specEdited: false })).toBeNull();
});
it('只包含被标记过的字段', () => {
const payload = buildBatchRowArchive(
{ spec: '约500g', brand: '蒙牛', origin: '内蒙古' },
{ brandEdited: true }
);
expect(payload).toEqual({ brand: '蒙牛' });
expect(Object.keys(payload!)).toEqual(['brand']);
});
it('表单 origin 映射到服务端契约名 manufacturer', () => {
expect(
buildBatchRowArchive({ spec: 'S', brand: 'B', origin: 'O' }, {
specEdited: true,
brandEdited: true,
originEdited: true,
})
).toEqual({ spec: 'S', brand: 'B', manufacturer: 'O' });
});
it('值两侧空白被裁掉;被标记的空串是一次真实的清空(仍要上报)', () => {
expect(buildBatchRowArchive({ spec: ' 5kg ' }, { specEdited: true })).toEqual({ spec: '5kg' });
expect(buildBatchRowArchive({ spec: '' }, { specEdited: true })).toEqual({ spec: '' });
});
it('标记了但值缺失 ⇒ 上报空串(不是 undefined)', () => {
expect(buildBatchRowArchive({}, { specEdited: true })).toEqual({ spec: '' });
});
});