oms/backend/test/app/lib/dgjProductSkuCoverage.test.js
liufumingren b63204d9fe fix(shop-product): 识别规格没拉全的商品,避免误判下架
平台 `SkuCount` 与实际下发的 `Skus` 会不一致:线上商品 3773823319627923739
`SkuCount=6`,`/Product/LoadList` 只回 3 个规格(分销/多来源商品常见),
库里有 4 行(含一个平台已不再返回的规格)。此前整份快照 verified 后,
那些「平台没返回」的规格会被当成平台已下架,直接删除或标下架,绑定关系跟着丢。

- dgj.listProducts:逐个商品比较 `SkuCount` 与实际下发的规格数,
  不一致就记入 `incompleteProducts: [{outer_item_id, expected, got}]` 并 warn 留痕
- controller.saveShopProducts:`incompleteProducts` 里的商品不参与「平台已下架」判定
  (既不删除也不标下架),其余商品行为不变
- 同步商品接口返回 incomplete / incomplete_products;contract 补
  externalPrintShopProductIncompleteItem
- 单测 dgjProductSkuCoverage.test.js 2 例(识别不全 / 一致时不标记)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 23:14:48 +08:00

72 lines
2.8 KiB
JavaScript
Raw Permalink 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');
describe('dgj.listProducts 规格不全的识别', () => {
it('平台 SkuCount 大于实际下发的 Skus 时标记为 incomplete,且不影响其它商品', async () => {
const service = new DgjService({ platform: { code: 'dgj', name: '店管家' }, account: { token: 't', cookie: 'c' } });
service.logger = { info() {}, warn() {}, error() {} };
service.getUserInfo = async () => ({ data: { TraceId: 'tr' } });
// 声明域名 → 一个分区快照,含两个商品:一个规格不全(6 报 3),一个正常
service.resolveProductHosts = () => [ 'fxdd.dgjapp.com' ];
service.fetchProductSnapshot = async () => ({
host: 'fxdd.dgjapp.com',
total: 2,
uniqueCount: 2,
pages: 1,
verified: true,
areas: [],
rows: [
{
PlatformId: '3773823319627923739',
SkuCount: 6,
Subject: '规格不全的商品',
Skus: [
{ Id: 1, SkuId: '3683584205645314', Name: 'A' },
{ Id: 2, SkuId: '3683584205645570', Name: 'B' },
{ Id: 3, SkuId: '3548726733104898', Name: 'C' },
],
},
{
PlatformId: '999',
SkuCount: 2,
Subject: '正常商品',
Skus: [
{ Id: 4, SkuId: '1001', Name: 'D' },
{ Id: 5, SkuId: '1002', Name: 'E' },
],
},
],
});
const snapshot = await service.listProducts({ external_data: { FxUserId: '953516', DbAreas: [] } });
console.log('list:', snapshot.list.length, 'incomplete:', JSON.stringify(snapshot.incompleteProducts));
assert.strictEqual(snapshot.list.length, 5, '两件商品共 5 个规格都写进 list');
assert.strictEqual(snapshot.incompleteProducts.length, 1);
assert.deepStrictEqual(snapshot.incompleteProducts[0], { outer_item_id: '3773823319627923739', expected: 6, got: 3 });
});
it('SkuCount 与实际一致时不标记', async () => {
const service = new DgjService({ platform: { code: 'dgj', name: '店管家' }, account: { token: 't', cookie: 'c' } });
service.logger = { info() {}, warn() {}, error() {} };
service.getUserInfo = async () => ({ data: {} });
service.resolveProductHosts = () => [ 'fxdd.dgjapp.com' ];
service.fetchProductSnapshot = async () => ({
host: 'fxdd.dgjapp.com',
total: 1,
uniqueCount: 1,
pages: 1,
verified: true,
areas: [],
rows: [{
PlatformId: '1',
SkuCount: 2,
Skus: [{ Id: 1, SkuId: 'a' }, { Id: 2, SkuId: 'b' }],
}],
});
const snapshot = await service.listProducts({ external_data: { FxUserId: '953516', DbAreas: [] } });
assert.deepStrictEqual(snapshot.incompleteProducts, []);
});
});