oms/backend/test/app/lib/dgjOrderPlatformRule.test.js
liufumingren 8ae6733e97 feat(dgj): 1688 快手分销单换算成快手(KS)取号
生产 `external_print_express_interfaces` 里快手(KS)有 2 个启用中的面单模板,
把 `kuaishou` 加进渠道映射表即可让快手分销单正常取号(之前落 OTHER,
取号直接报「平台OTHER(其他)暂无面单模板」)。

- DISTRIBUTE_CHANNEL_PLATFORM 增加 kuaishou → KS
- 单测补 1 例:OutChannel=kuaishou → KS / 快手,原始平台仍留痕 1688

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-08 18:49:15 +08:00

137 lines
6.3 KiB
JavaScript
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.

'use strict';
const { assert } = require('egg-mock/bootstrap');
const DgjService = require('../../../app/lib/printPlatform/dgj');
/** 构造一个最小可用的店管家平台服务(normalizeOrder 不触网) */
function buildService() {
return new DgjService({ platform: { code: 'dgj', name: '店管家' }, account: { token: 't', cookie: 'c' } });
}
/**
* 造一条店管家订单行
* @param overrides
*/
function buildRow(overrides = {}) {
return {
LogicOrderId: '10000279767413',
PlatformOrderId: '5127406131122008631',
PlatformType: 'Alibaba',
ShopId: '7398588',
ShopName: '13668975305(意洁)',
ErpState: 'waitsellersend',
CreateTime: '2026-11-06 10:00:00',
UpdateTime: '2026-11-06 10:05:00',
TotalAmount: 10,
ToName: '张三',
ToPhone: '13800000000',
SubOrders: [{ OrderItemId: '1', ProductID: '100', Count: 1, Price: 10, OrderItemCode: 'SKU-1' }],
...overrides,
};
}
describe('printPlatform/dgj normalizeOrder 平台换算硬规则', () => {
const service = buildService();
it('1688 抖音分销单 → 抖音小店', () => {
const row = buildRow({
Tags: [{ Tag: 'OutChannel', TagValue: 'douyin', Platform: 'Alibaba' }],
});
const order = service.normalizeOrder(row);
console.log('抖音分销:', order.platform_code, order.platform_name, order.distribute_channel, order.original_platform_code);
assert.strictEqual(order.platform_code, 'DYXD');
assert.strictEqual(order.platform_name, '抖音小店');
assert.strictEqual(order.distribute_channel, 'douyin');
assert.strictEqual(order.original_platform_code, '1688');
// 原始平台类型仍留痕
assert.strictEqual(order.platform_type, 'Alibaba');
});
it('1688 抖音分销单(明文后缀 douyin_plaintext)同样换算成抖音小店', () => {
const row = buildRow({
ExtField1: 'douyin',
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'douyin_plaintext' }],
OrderTags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'douyin_plaintext' }],
});
const order = service.normalizeOrder(row);
console.log('抖音分销(明文):', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'DYXD');
assert.strictEqual(order.platform_name, '抖音小店');
// 渠道原值留痕(归一化只用于平台换算)
assert.strictEqual(order.distribute_channel, 'douyin_plaintext');
});
it('1688 分销单没有 OutChannel 标签时用 ExtField1 兜底识别渠道', () => {
const order = service.normalizeOrder(buildRow({ ExtField1: 'douyin', Tags: [] }));
console.log('ExtField1 兜底:', order.platform_code, order.distribute_channel);
assert.strictEqual(order.platform_code, 'DYXD');
assert.strictEqual(order.distribute_channel, 'douyin');
});
it('1688 单既无标签又无 ExtField1 仍按淘宝(非分销单)', () => {
const order = service.normalizeOrder(buildRow({ ExtField1: '', Tags: [], OrderTags: [] }));
assert.strictEqual(order.platform_code, 'TB');
assert.strictEqual(order.distribute_channel, null);
});
it('其它平台的 ExtField1(快手单里是哈希)不会被当成分销渠道', () => {
const order = service.normalizeOrder(buildRow({ PlatformType: 'KuaiShou', ExtField1: 'cb82842eb4b1a919', Tags: [] }));
assert.strictEqual(order.platform_code, 'KS');
assert.strictEqual(order.distribute_channel, null);
});
it('1688 非分销单(无 OutChannel 标签)→ 淘宝', () => {
const order = service.normalizeOrder(buildRow({ Tags: [] }));
console.log('非分销:', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'TB');
assert.strictEqual(order.platform_name, '淘宝');
assert.strictEqual(order.distribute_channel, null);
assert.strictEqual(order.original_platform_code, '1688');
});
it('1688 快手分销单 → 快手(KS),生产有快手模板', () => {
const order = service.normalizeOrder(buildRow({
ExtField1: 'kuaishou',
Tags: [{ Tag: 'OutChannel', TagType: 'Order', TagValue: 'kuaishou' }],
}));
console.log('快手分销:', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'KS');
assert.strictEqual(order.platform_name, '快手');
assert.strictEqual(order.distribute_channel, 'kuaishou');
assert.strictEqual(order.original_platform_code, '1688');
});
it('1688 未识别的分销渠道 → 其他(保留渠道与原始报文)', () => {
const order = service.normalizeOrder(buildRow({
Tags: [{ Tag: 'OutChannel', TagValue: 'thyny_plaintext' }],
}));
console.log('未知渠道:', order.platform_code, order.platform_name, order.distribute_channel);
assert.strictEqual(order.platform_code, 'OTHER');
assert.strictEqual(order.platform_name, '其他');
assert.strictEqual(order.distribute_channel, 'thyny_plaintext');
assert.strictEqual(order.original_platform_code, '1688');
// 原始报文完整保留(后续再做渠道映射时要用)
assert.deepStrictEqual(order.raw.Tags, [{ Tag: 'OutChannel', TagValue: 'thyny_plaintext' }]);
assert.strictEqual(order.platform_type, 'Alibaba');
});
it('换算后取号/回读仍按原始平台选订单域名', () => {
// 1688 分销单换算成抖音小店,但订单数据仍在 1688 域名下
assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('1688')), 'fxali.dgjapp.com');
// 真实抖音单/淘宝单各自域名不变(淘宝与 1688 同域,走兜底 fxali)
assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('DYXD')), 'fxdd.dgjapp.com');
assert.strictEqual(DgjService.resolveOrderHost(DgjService.resolvePlatformType('TB')), 'fxali.dgjapp.com');
});
it('其它平台不受该硬规则影响', () => {
const taobao = service.normalizeOrder(buildRow({ PlatformType: 'Taobao', Tags: [] }));
assert.strictEqual(taobao.platform_code, 'TB');
const douyin = service.normalizeOrder(buildRow({ PlatformType: 'TouTiao', Tags: [] }));
assert.strictEqual(douyin.platform_code, 'DYXD');
const pdd = service.normalizeOrder(buildRow({ PlatformType: 'Pinduoduo', Tags: [] }));
assert.strictEqual(pdd.platform_code, 'PDD');
});
});