oms/backend/test/app/lib/dgjMyShopList.test.js
liufumingren c27ea5a789 feat(shop): 店管家接入「我的店铺」第二来源,支持拉取店铺并绑定货主
- 平台层新增 listShopSources() / resolveShopScope() 契约,来源由平台实现声明,控制器与前端不写死
- 店管家实现 my_shop 来源:POST /partner/LoadMyShopList 店铺列表(授权状态、平台、名称过滤)并归一化
- 新增 GET /api/external-print-accounts/:id/shop-sources;店铺列表接口支持 ?source=
- 店铺创建支持 source,写入 shops.external_source;编码 dgj-{账号ID}-{来源}-{ShopId},默认来源不加来源段
- 新增迁移 shops.external_source(默认 agent);刷新所在区只处理默认来源,避免自营店被误判解绑而自动禁用
- my_shop 的拉单/拉商品暂时明确拒绝,防止按账号 FxUserId 拉到上游其它数据(下一步接入)
- 前端「店铺列表」弹窗支持来源切换,展示平台、授权状态与服务到期时间
- 补充单元测试与文档(店管家取号-旧系统提取 §4.2.1.1)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-09 02:42:24 +08:00

140 lines
5.7 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');
/**
* 构造一个只用于纯函数校验的店管家服务实例(不会发请求)
* @return {DgjService} 服务实例
*/
function createService() {
return new DgjService({
platform: { code: 'dgj', name: '店管家', url: 'fxali.dgjapp.com' },
account: { token: 'token', cookie: 'cookie' },
});
}
describe('printPlatform/dgj listShopSources', () => {
it('默认来源为平台商家,且包含我的店铺', () => {
const sources = createService().listShopSources();
assert.deepStrictEqual(sources.map(item => item.code), [ 'agent', 'my_shop' ]);
assert.strictEqual(sources[0].name, '平台商家');
});
});
describe('printPlatform/dgj normalizeMyShop', () => {
const service = createService();
it('授权成功:启用、平台编码映射到系统预设', () => {
const item = service.normalizeMyShop({
ShopId: 12345897,
ShopNameRemark: 'Moocola个人护理旗舰店',
NickName: 'Moocola',
PlatformType: 'TouTiao',
PlatformTypeName: '抖店',
Status: 1,
IsExpire: false,
IsAuthExpired: false,
AuthTime: '2026-12-07 21:23:16',
});
assert.strictEqual(item.source, 'my_shop');
assert.strictEqual(item.external_id, '12345897');
assert.strictEqual(item.name, 'Moocola个人护理旗舰店');
assert.strictEqual(item.status, 1);
assert.strictEqual(item.status_label, '正常');
assert.strictEqual(item.platform_code, 'DYXD');
assert.strictEqual(item.platform_name, '抖店');
assert.strictEqual(item.platform_type, 'TouTiao');
assert.strictEqual(item.auth_expired, false);
assert.strictEqual(item.service_expired, false);
assert.strictEqual(item.auth_time, '2026-12-07 21:23:16');
});
it('授权过期(Status=3):禁用并给出「授权过期」', () => {
const item = service.normalizeMyShop({ ShopId: 1, ShopNameRemark: '过期店', PlatformType: 'KuaiShou', Status: 3, IsAuthExpired: true });
assert.strictEqual(item.status, 0);
assert.strictEqual(item.status_label, '授权过期');
assert.strictEqual(item.auth_expired, true);
assert.strictEqual(item.platform_code, 'KS');
});
it('服务到期但授权仍有效:保持启用,文案为「服务到期」', () => {
const item = service.normalizeMyShop({ ShopId: 2, ShopNameRemark: '临期店', PlatformType: 'XiaoHongShu', Status: 1, IsExpire: true });
assert.strictEqual(item.status, 1);
assert.strictEqual(item.status_label, '服务到期');
assert.strictEqual(item.service_expired, true);
assert.strictEqual(item.platform_code, 'XHS');
});
it('线下单映射到线下,名称缺失时兜底为空串', () => {
const item = service.normalizeMyShop({ ShopId: 3, PlatformType: 'Virtual', Status: 1 });
assert.strictEqual(item.platform_code, 'OFFLINE');
assert.strictEqual(item.name, '');
});
});
describe('printPlatform/dgj resolveShopScope', () => {
const service = createService();
it('我的店铺:按 ShopId 定位,域名由 PlatformType 推导', () => {
const scope = service.resolveShopScope({
code: 'dgj-1-my_shop-12345897',
external_source: 'my_shop',
external_data: { ShopId: 12345897, PlatformType: 'TouTiao' },
});
assert.deepStrictEqual(scope, {
source: 'my_shop',
externalId: '12345897',
shopId: '12345897',
platformType: 'TouTiao',
hosts: [ 'fxdd.dgjapp.com' ],
});
});
it('平台商家:按商家 Id 定位,域名由分区声明推导', () => {
const scope = service.resolveShopScope({
code: 'dgj-1-7251148',
external_source: 'agent',
external_data: { Id: 7251148, FxUserId: 953516, DbAreas: [{ DbName: 'alibaba' }] },
});
assert.strictEqual(scope.source, 'agent');
assert.strictEqual(scope.externalId, '7251148');
assert.deepStrictEqual(scope.hosts, [ 'fxali.dgjapp.com' ]);
});
it('来源缺省时按平台商家处理(兼容老数据)', () => {
const scope = service.resolveShopScope({ code: 'dgj-1-100', external_data: { Id: 100 } });
assert.strictEqual(scope.source, 'agent');
assert.strictEqual(scope.externalId, '100');
});
});
describe('printPlatform/dgj 我的店铺暂不支持拉单/拉商品', () => {
const service = createService();
const shop = { external_source: 'my_shop', external_data: { ShopId: 12345897, FxUserId: 1227061, PlatformType: 'TouTiao' } };
it('listOrders 明确拒绝,避免按账号 FxUserId 拉到别人的订单', async () => {
await assert.rejects(() => service.listOrders(shop, {}), /暂未支持拉取订单/);
});
it('listProducts 明确拒绝,避免按账号 FxUserId 拉到别人的商品', async () => {
await assert.rejects(() => service.listProducts(shop), /暂未支持同步商品/);
});
});
describe('printPlatform/dgj resolveMyShopHost', () => {
const service = createService();
it('按平台类型映射到订单/商品接口域名', () => {
assert.strictEqual(service.resolveMyShopHost('TouTiao'), 'fxdd.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('Pinduoduo'), 'fxpdd.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('Jingdong'), 'fxjd.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('Taobao'), 'fxali.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('KuaiShou'), 'fxali.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('WxVideo'), 'fxali.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('XiaoHongShu'), 'fxali.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost('Virtual'), 'fxali.dgjapp.com');
assert.strictEqual(service.resolveMyShopHost(''), 'fxali.dgjapp.com');
});
});