'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), ''); }); });