- 推送前校验改为「能否解析到系统商品」:product_id / combo_product_id / 历史手工单 item_id(与商品编码一致)/ 无平台溯源时编码命中商品库 - 平台未绑定明细(带店铺商品 / 平台快照 / 平台商品ID)仍然拦截并提示先在「店铺商品」绑定 - 建单 / 改单写库时把历史手工单误存在 item_id 里的系统商品ID 迁到 product_id,并补 item_type / parse_status - 推送报文 itemId 优先用仓库映射(warehouse_products.wms_item_id),避免把系统商品ID 当 WMS 商品ID 下发 - 手工单表单改用 product_id 记录所选系统商品(item_id 仅沿用历史数据) - 新增 orderPushItems 与推送报文 itemId 单测 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
74 lines
3.3 KiB
JavaScript
74 lines
3.3 KiB
JavaScript
'use strict';
|
||
|
||
const { assert } = require('egg-mock/bootstrap');
|
||
const { findUnconvertibleItems, unconvertibleMessage, hasPlatformTrace } = require('../../../app/lib/orderPushItems');
|
||
|
||
const PRODUCTS = [
|
||
{ id: 4, item_code: 'P260911231515227608' },
|
||
{ id: 24, item_code: 'P261105011902808526' },
|
||
{ id: 30, item_code: 'tbcs111' },
|
||
];
|
||
|
||
describe('test/app/lib/orderPushItems.test.js', () => {
|
||
it('已绑定系统商品 / 组合拆分子行可推送', () => {
|
||
const items = [
|
||
{ order_line_no: '1', product_id: 4, item_code: 'P260911231515227608' },
|
||
{ order_line_no: '2', product_id: 24, combo_product_id: 9, item_code: 'P261105011902808526' },
|
||
];
|
||
assert(findUnconvertibleItems(items, PRODUCTS).length === 0);
|
||
});
|
||
|
||
it('平台未绑定明细(带平台溯源、平台编码)不可推送', () => {
|
||
const items = [
|
||
{ order_line_no: '1', shop_product_id: 1466, item_code: 'wf-C05速干定型喷雾420*3+排骨梳*1', parse_status: 2 },
|
||
];
|
||
const invalid = findUnconvertibleItems(items, PRODUCTS);
|
||
assert(invalid.length === 1);
|
||
const message = unconvertibleMessage(invalid);
|
||
assert(message.includes('第 1 行'));
|
||
assert(message.includes('店铺商品'));
|
||
});
|
||
|
||
it('历史手工单:item_id 存系统商品ID 且编码一致 → 可推送', () => {
|
||
const items = [{ order_line_no: '1', item_id: 24, item_code: 'P261105011902808526' }];
|
||
assert(findUnconvertibleItems(items, PRODUCTS).length === 0);
|
||
});
|
||
|
||
it('item_id 不能凭商品ID 放行,编码必须命中系统商品', () => {
|
||
const wrong = [{ order_line_no: '1', item_id: 4, item_code: 'NOT-EXIST' }];
|
||
assert(findUnconvertibleItems(wrong, PRODUCTS).length === 1);
|
||
const byCode = [{ order_line_no: '1', item_id: 4, item_code: 'P261105011902808526' }];
|
||
assert(findUnconvertibleItems(byCode, PRODUCTS).length === 0);
|
||
});
|
||
|
||
it('手工单只有商品编码且命中系统商品 → 可推送', () => {
|
||
const items = [{ order_line_no: '1', item_code: 'tbcs111' }];
|
||
assert(findUnconvertibleItems(items, PRODUCTS).length === 0);
|
||
});
|
||
|
||
it('带平台溯源的明细即使编码命中系统商品也不放行(必须先绑定店铺商品)', () => {
|
||
const items = [
|
||
{ order_line_no: '1', item_code: 'tbcs111', shop_product_id: 1382 },
|
||
{ order_line_no: '2', item_code: 'tbcs111', platform_snapshot: { item_code: 'tbcs111' } },
|
||
{ order_line_no: '3', item_code: 'tbcs111', outer_item_id: '10000202451115' },
|
||
];
|
||
const invalid = findUnconvertibleItems(items, PRODUCTS);
|
||
assert(invalid.length === 3);
|
||
});
|
||
|
||
it('product_id 不属于本主体商品库时按编码兜底(带平台溯源的仍拦下)', () => {
|
||
const items = [{ order_line_no: '1', product_id: 999, item_code: 'P260911231515227608' }];
|
||
assert(findUnconvertibleItems(items, PRODUCTS).length === 0);
|
||
const platform = [{ order_line_no: '1', product_id: 999, item_code: 'P260911231515227608', shop_product_id: 1 }];
|
||
assert(findUnconvertibleItems(platform, PRODUCTS).length === 1);
|
||
});
|
||
|
||
it('hasPlatformTrace 只看平台溯源字段', () => {
|
||
assert(hasPlatformTrace({ shop_product_id: 1 }));
|
||
assert(hasPlatformTrace({ platform_snapshot: {} }));
|
||
assert(hasPlatformTrace({ outer_item_id: 'x' }));
|
||
assert(!hasPlatformTrace({ item_code: 'x' }));
|
||
assert(!hasPlatformTrace(null));
|
||
});
|
||
});
|