拉单结果只报「新增 0 / 更新 N」,用户会以为「拉到 8 单却没落库」。 实际是拉单按平台单号(老表 orders.order_no = 平台code-平台单号)去重: 已在系统里的单只刷新平台状态与收件人,不会重复新增,也不会把已审核过的单退回待审核。 - externalPrintOrder.buildRefreshHint:created=0 且 updated>0 时给出说明 (已在「待推送 / 配送 / 历史」,或因平台侧已发货被自动作废,可按平台单号搜索) - 接进 syncOrders 的 hint 链(零单/补查/兜底都不命中时才用) - 单测补 1 例(含「有新增不提示」「0 更新不提示」) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
101 lines
4.0 KiB
JavaScript
101 lines
4.0 KiB
JavaScript
'use strict';
|
||
|
||
const { app, assert } = require('egg-mock/bootstrap');
|
||
|
||
describe('service/externalPrintOrder 拉单 0 单的排查提示', () => {
|
||
let service;
|
||
|
||
beforeEach(() => {
|
||
service = app.mockContext().service.externalPrintOrder;
|
||
});
|
||
|
||
it('平台出现了别的商家、没出现本店商家时给出提示', () => {
|
||
const hint = service.buildZeroOrderHint(
|
||
{ external_data: { FxUserId: 1921984 } },
|
||
{
|
||
total: 0,
|
||
merchantSeen: false,
|
||
otherMerchants: [{ fx_user_id: '953516', shop_name: '13668975305(意洁)', count: 450 }],
|
||
hosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
|
||
fallbackHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
|
||
},
|
||
{ startTime: new Date('2026-10-23T00:00:00Z'), endTime: new Date('2026-11-07T00:00:00Z') }
|
||
);
|
||
console.log('提示:', hint);
|
||
assert.match(hint, /近 15 天/);
|
||
assert.match(hint, /FxUserId=1921984/);
|
||
assert.match(hint, /953516/);
|
||
assert.match(hint, /刷新/);
|
||
// 分区去重
|
||
assert.strictEqual(hint.split('抖店-186').length - 1, 1);
|
||
});
|
||
|
||
it('有单 / 商家出现过 / 没看到别的商家时都不提示', () => {
|
||
const shop = { external_data: { FxUserId: 1 } };
|
||
const base = { merchantSeen: false, otherMerchants: [{ fx_user_id: '2', shop_name: 'A', count: 3 }], hosts: [] };
|
||
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 5 }), '');
|
||
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 0, merchantSeen: true }), '');
|
||
assert.strictEqual(service.buildZeroOrderHint(shop, { ...base, total: 0, otherMerchants: [] }), '');
|
||
assert.strictEqual(service.buildZeroOrderHint(shop, null), '');
|
||
});
|
||
|
||
it('声明分区没拉到单、补查其它域名才拉到时给出提示', () => {
|
||
const hint = service.buildSupplementHint(
|
||
{ external_data: { FxUserId: 953516 } },
|
||
{
|
||
total: 6,
|
||
declaredHosts: [ 'fxdd.dgjapp.com' ],
|
||
supplementHosts: [ 'fxali.dgjapp.com', 'fxpdd.dgjapp.com' ],
|
||
}
|
||
);
|
||
console.log('补查提示:', hint);
|
||
assert.match(hint, /fxdd\.dgjapp\.com/);
|
||
assert.match(hint, /fxali\.dgjapp\.com/);
|
||
assert.match(hint, /拉到 6 单/);
|
||
assert.match(hint, /刷新/);
|
||
});
|
||
|
||
it('没补查 / 没拉到单时不提示', () => {
|
||
assert.strictEqual(service.buildSupplementHint({}, { total: 6, supplementHosts: [] }), '');
|
||
assert.strictEqual(service.buildSupplementHint({}, { total: 0, supplementHosts: [ 'fxali.dgjapp.com' ] }), '');
|
||
assert.strictEqual(service.buildSupplementHint({}, null), '');
|
||
});
|
||
|
||
it('补扫老分区才拉到单时也算补查', () => {
|
||
const hint = service.buildSupplementHint({}, {
|
||
total: 5,
|
||
declaredHosts: [ 'fxdd.dgjapp.com' ],
|
||
rescueHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
|
||
});
|
||
console.log('补扫老分区提示:', hint);
|
||
assert.match(hint, /抖店-186/);
|
||
assert.match(hint, /拉到 5 单/);
|
||
});
|
||
|
||
it('走了「不支持状态过滤 → 全量」兜底时提示可能漏单', () => {
|
||
const hint = service.buildFallbackHint({
|
||
total: 0,
|
||
fallbackHosts: [ 'fxdd.dgjapp.com(抖店-186)' ],
|
||
});
|
||
console.log('兜底提示:', hint);
|
||
assert.match(hint, /抖店-186/);
|
||
assert.match(hint, /全量列表不含待发货单/);
|
||
assert.match(hint, /单个等号/);
|
||
assert.strictEqual(service.buildFallbackHint({ total: 0, fallbackHosts: [] }), '');
|
||
assert.strictEqual(service.buildFallbackHint(null), '');
|
||
});
|
||
|
||
it('全部都是更新、没有新增时说明「已在系统里、不会退回待审核」', () => {
|
||
const hint = service.buildRefreshHint({ created: 0, updated: 8 });
|
||
console.log('全更新提示:', hint);
|
||
assert.match(hint, /8 单/);
|
||
assert.match(hint, /都已存在/);
|
||
assert.match(hint, /待推送/);
|
||
assert.match(hint, /自动作废/);
|
||
// 有新增时不提示
|
||
assert.strictEqual(service.buildRefreshHint({ created: 2, updated: 8 }), '');
|
||
assert.strictEqual(service.buildRefreshHint({ created: 0, updated: 0 }), '');
|
||
assert.strictEqual(service.buildRefreshHint(null), '');
|
||
});
|
||
});
|