oms/backend/test/app/lib/pullOrderHint.test.js
liufumingren f47d8ccdec fix(pull): 声明分区过期时补查其它域名 + 商家ID失效按名称重绑
用户现象:意洁点「拉取订单」0 单,但店管家 UI(精选-二区)有单;「同步商品」
同样 0 条,而「按商品ID补拉」能拿到 —— 说明不是没有数据,是**全量拉取只查了店铺
声明的域名/分区声明**(external_data.DbAreas)里那几块,声明过期就永远拉不到。

- dgj.listOrders:声明域名一单都没拉到(且没有平台已发货登记)时,补查账号其它域名
  (FALLBACK_PRODUCT_HOSTS 里未声明的),命中记入 supplementHosts 并 warn;
  「按商品ID补拉」本来就是这个兜底策略,现在全量拉取也一致
- dgj.listProducts:声明域名一个商品都没有时同样补查其它域名
- externalPrintOrder:新增 buildSupplementHint —— 靠补查才拉到单时提示
  「店铺声明的分区 X 没拉到单,已自动补查 Y 并拉到 N 单;建议刷新店铺所在区/商家」
- shopAreaSync:商家ID在平台已不存在时,先按店铺名称在商家列表里找**唯一**候选并
  重新绑定(rebound,写 warn 日志);同名多候选/已被别的店铺占用/无名称时不猜,
  保持原有「标记已解绑并自动禁用」逻辑
  → 修掉「重新授权/换绑后商家ID变了,店铺被当成已解绑而禁用,拉单一律 0」

验证:
- 单测 shopAreaSync.test.js(唯一命中 / 同名多候选 / 已占用 / 空名称)、
  pullOrderHint.test.js 补 3 例(补查提示与边界),test/app/lib 73 passing
- 真实库:把意洁店铺的 extId 改坏后 refreshAccount → 按名称重绑回 3966847、
  FxUserId 恢复 953516、状态未被禁用;再刷新 5 个店铺 missing/disabled 均为空;
  声明域名只保留 toutiao 时应能靠补查把抖店 6 单拉回来(已单测覆盖提示口径)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 19:40:33 +08:00

64 lines
2.5 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 { 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), '');
});
});