feat(京东跨店上架): 用户端 cross 档 + 目标店二次确认 + 协议 4 闸
客户口径「要跨店」:异店不再硬拦,改成显形目标店 + 风险确认后建单(客户端走京麦新增商品)。 - jd-publish-shop:evaluateShopGuard 加 cross 态(目标店=京麦当前登录店); shopGuardBlocks/shopGuardMessage 接受 crossAllowed,协议 <4 时仍拦并给升级文案 - JdPublishTab:跨店显形「目标店(跨店)」行、琥珀风险句(会在目标店新建商品并过京东审核、 目标店须已授权该类目)、原生勾选二次确认作硬闸;按钮文案改「跨店上架 N 个商品到目标店」; 协议 >=4 才放行;建单请求带 targetShopId/targetShopName - api:createJdPublishTask 增加可选 targetShop,body 按需带两个键 判据:jd-publish-shop.test.ts 17 支(cross 五态、跨店文案不写「稍后重试」、协议常量与源码绊线)、 mount 32 支(协议 3 只给升级提示不建单、协议 4 确认后带目标店建单);三次反向验证改坏即红。 node --test 1147/vitest 149/vue-tsc --noEmit rc=0;可读基线 JdPublishTab.vue 1014→1075 逐条点名。
This commit is contained in:
@@ -9,22 +9,28 @@ import {
|
||||
resolveJdPublishAccess,
|
||||
} from '../src/pages/jd/jd-publish-access.ts'
|
||||
import {
|
||||
CROSS_UPGRADE_NOTICE,
|
||||
JD_PUBLISH_BRAND_PROTOCOL,
|
||||
JD_PUBLISH_CROSS_PROTOCOL,
|
||||
crossShopMessage,
|
||||
evaluateShopGuard,
|
||||
normalizeShopRef,
|
||||
shopGuardBlocks,
|
||||
shopGuardMessage,
|
||||
shopLabel,
|
||||
shopMismatchMessage,
|
||||
SHOP_MISMATCH_MARK,
|
||||
sourceShopRefs,
|
||||
} from '../src/pages/jd/jd-publish-shop.ts'
|
||||
|
||||
/**
|
||||
* 2026-11-24 客户口径两件(京东「商品上架」):
|
||||
* 1. 「如果没有店铺登入情况 软件怎么知道我们要上架是哪一个店铺?」——页面必须显形
|
||||
* 来源店铺与京麦当前登录店铺,不一致强拦截;
|
||||
* 来源店铺与京麦当前登录店铺;
|
||||
* 2. 「上架的账户 我是这个权限不开给他的」——按账号授权:入口隐藏(卡片过滤)+
|
||||
* 直达路由守卫+服务端 403 三层。
|
||||
*
|
||||
* 2026-11-26 客户口径「要跨店」:异店从「硬拦」改成「跨店档」——目标店=京麦当前登录店,
|
||||
* 客户端走京麦「新增商品」路径;本机协议 < 4 时仍拦(老客户端没有新增路径)。
|
||||
*
|
||||
* 本文件管纯判据与源码绊线;页面接线由 tests/mount/jd-publish-dispatch.mount.test.ts 覆盖。
|
||||
*/
|
||||
|
||||
@@ -67,37 +73,56 @@ test('店铺标签:名+id 全显示,缺一半只报有的那半,全空=
|
||||
assert.equal(normalizeShopRef({ shopId: ' ' }), null)
|
||||
})
|
||||
|
||||
test('不匹配文案:标记开头、点名两家店、给动作句且不写「稍后重试」', () => {
|
||||
const message = shopMismatchMessage(
|
||||
test('跨店文案:点名来源店与目标店、说明会新建商品要过审、要求目标店已授权类目,不写「稍后重试」', () => {
|
||||
const message = crossShopMessage(
|
||||
{ shopId: '148191738', shopName: '汽车用品数据库店' },
|
||||
{ shopId: '228346061', shopName: '家居日用数据库店' },
|
||||
{ shopId: '165515933', shopName: '花屿巷旗舰店' },
|
||||
)
|
||||
assert.ok(message.startsWith(SHOP_MISMATCH_MARK))
|
||||
assert.ok(message.startsWith('跨店上架'))
|
||||
assert.ok(message.includes('汽车用品数据库店') && message.includes('148191738'))
|
||||
assert.ok(message.includes('家居日用数据库店') && message.includes('228346061'))
|
||||
assert.ok(message.includes('花屿巷旗舰店') && message.includes('165515933'))
|
||||
assert.ok(message.includes('切换'))
|
||||
assert.ok(message.includes('新建'), '必须说清跨店是在目标店新建商品')
|
||||
assert.ok(message.includes('授权'), '必须点名目标店类目授权这个硬前提')
|
||||
assert.ok(message.includes('审核'), '必须说清要过京东审核')
|
||||
assert.ok(!message.includes('稍后重试'), '确定性失败不允许写「稍后重试」')
|
||||
})
|
||||
|
||||
test('判据四态:未勾选 unknown / 未检测 undetected / 同店 match / 异店 mismatch', () => {
|
||||
test('判据五态:未勾选 unknown / 未检测 undetected / 同店 match / 异店 cross / 多店 multi', () => {
|
||||
assert.equal(evaluateShopGuard([], { shopId: '1' }).state, 'unknown')
|
||||
assert.equal(evaluateShopGuard([{ shopId: '1' }], null).state, 'undetected')
|
||||
const match = evaluateShopGuard([{ shopId: '1', shopName: '某店' }], { shopId: '1', shopName: '某店' })
|
||||
assert.equal(match.state, 'match')
|
||||
const mismatch = evaluateShopGuard([{ shopId: '1', shopName: '某店' }], { shopId: '2', shopName: '别店' })
|
||||
assert.equal(mismatch.state, 'mismatch')
|
||||
assert.ok(shopGuardBlocks(mismatch))
|
||||
const cross = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }], { shopId: '2', shopName: '乙店' })
|
||||
assert.equal(cross.state, 'cross')
|
||||
if (cross.state === 'cross') {
|
||||
assert.equal(cross.target.shopId, '2', '目标店=京麦当前登录店(不是来源店)')
|
||||
assert.ok(cross.message.includes('乙店'))
|
||||
}
|
||||
assert.ok(!shopGuardBlocks(match) && !shopGuardBlocks(evaluateShopGuard([], null)))
|
||||
})
|
||||
|
||||
test('id 优先于店名:id 不同但同名也不放行', () => {
|
||||
const guard = evaluateShopGuard([{ shopId: '1', shopName: '同名店' }], { shopId: '2', shopName: '同名店' })
|
||||
assert.equal(guard.state, 'mismatch')
|
||||
test('跨店档默认拦(本机协议不够),显式允许后才放行;提示换升级文案', () => {
|
||||
const cross = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }], { shopId: '2', shopName: '乙店' })
|
||||
assert.ok(shopGuardBlocks(cross), '默认(协议 < 4)必须拦,老客户端没有新增商品路径')
|
||||
assert.equal(shopGuardMessage(cross), CROSS_UPGRADE_NOTICE)
|
||||
assert.ok(shopGuardMessage(cross).includes('升级'))
|
||||
assert.equal(shopGuardMessage(cross, true), '', '协议 ≥4 时跨店可建单')
|
||||
assert.ok(!shopGuardBlocks(cross, true))
|
||||
})
|
||||
|
||||
test('只有店名时按店名比对;比不了(一边只有 id)按未检测处理,不误拦', () => {
|
||||
test('协议门槛常量与服务端/客户端代次同档(品牌 3、跨店 4)', () => {
|
||||
assert.equal(JD_PUBLISH_BRAND_PROTOCOL, 3)
|
||||
assert.equal(JD_PUBLISH_CROSS_PROTOCOL, 4)
|
||||
})
|
||||
|
||||
test('id 优先于店名:id 不同但同名按跨店处理(不是同店)', () => {
|
||||
const guard = evaluateShopGuard([{ shopId: '1', shopName: '同名店' }], { shopId: '2', shopName: '同名店' })
|
||||
assert.equal(guard.state, 'cross')
|
||||
})
|
||||
|
||||
test('只有店名时按店名比对;比不了(一边只有 id)按未检测处理,不误判跨店', () => {
|
||||
assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '某店' }).state, 'match')
|
||||
assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '别店' }).state, 'mismatch')
|
||||
assert.equal(evaluateShopGuard([{ shopName: '某店' }], { shopName: '别店' }).state, 'cross')
|
||||
assert.equal(evaluateShopGuard([{ shopId: '1' }], { shopName: '某店' }).state, 'undetected')
|
||||
})
|
||||
|
||||
@@ -148,6 +173,17 @@ test('上架页不得自己拼店铺身份(只用勾选商品快照 + 桥结
|
||||
assert.ok(!tab.includes('jd-shop-info'), '页面不得自拼店铺读取 URL(唯一口是桥)')
|
||||
})
|
||||
|
||||
test('跨店接线:建单把目标店交给服务端、协议按最低档判定、二次确认是硬闸', () => {
|
||||
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
|
||||
assert.ok(tab.includes('targetShop'), '跨店建单必须把目标店(京麦当前登录店)传给服务端')
|
||||
assert.ok(tab.includes('JD_PUBLISH_CROSS_PROTOCOL'), '跨店协议闸必须引用常量单出口')
|
||||
assert.ok(tab.includes('crossConfirmed'), '跨店必须人工二次确认(会在目标店新建商品并过审)')
|
||||
assert.ok(!/jd_publish_protocol[^\n]*===\s*3/.test(tab), '协议判定不得再等值钉 3(v4 是 v3 的超集)')
|
||||
const api = read('src/shared/api/types/modules/jd-publish.ts', 'jd-publish API')
|
||||
assert.ok(api.includes('targetShopId') && api.includes('targetShopName'),
|
||||
'建单请求体必须带 targetShopId/targetShopName 两个键(服务端据此算 publishMode)')
|
||||
})
|
||||
|
||||
test('/jd-publish 直达路由挂权限守卫,权限接口失败按放行处理', () => {
|
||||
const router = read('src/router/index.ts', 'router/index.ts')
|
||||
assert.ok(router.includes('resolveJdPublishAccess'), '路由必须用统一判据模块')
|
||||
|
||||
@@ -117,12 +117,11 @@ it('建单只原样投递服务端载荷,网页不激活任务', async () => {
|
||||
expect(api.activate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it.each(['没有桥', '旧桥', '旧协议', '字符串协议', '未知协议', '协议异常'])('%s不允许建品牌单', async (failure) => {
|
||||
it.each(['没有桥', '旧桥', '旧协议', '字符串协议', '协议异常'])('%s不允许建品牌单', async (failure) => {
|
||||
if (failure === '没有桥') api.bridge.mockReturnValue(undefined)
|
||||
if (failure === '旧桥') api.bridge.mockReturnValue({ enqueue_json: api.enqueue })
|
||||
if (failure === '旧协议') api.protocol.mockResolvedValue(2)
|
||||
if (failure === '字符串协议') api.protocol.mockResolvedValue('3')
|
||||
if (failure === '未知协议') api.protocol.mockResolvedValue(4)
|
||||
if (failure === '协议异常') api.protocol.mockRejectedValue(new Error('bridge unavailable'))
|
||||
const page = await mountPage()
|
||||
await startPublish(page)
|
||||
@@ -359,8 +358,9 @@ it('源商品身份缺失形状已被客户端放行,提示维持换店或重
|
||||
})
|
||||
|
||||
// ---- 店铺核对(2026-11-24 客户口径「软件怎么知道要上架哪一家店铺」)----
|
||||
// 桥 get_jd_shop_info 现拉京麦当前登录店铺;与勾选商品的来源店铺不一致 ⇒ 页面强拦截,一条都不建单。
|
||||
// 老客户端没有这个方法(默认替身就不带)⇒ 不拦,最终拦截由客户端执行器与服务端完成。
|
||||
// 桥 get_jd_shop_info 现拉京麦当前登录店铺:同店照常;异店=跨店档(2026-11-26 客户口径「要跨店」):
|
||||
// 协议 ≥4 时显形目标店+风险句+二次确认后建单(服务端算 publishMode=NEW),协议 3 的老客户端
|
||||
// 仍只给升级提示、一条都不建单。老客户端没有这个方法(默认替身就不带)⇒ 不拦,最终拦截在客户端执行器。
|
||||
|
||||
type ShopBridgeResult = {
|
||||
success: boolean; shopId?: string; shopName?: string; code?: string; error?: string
|
||||
@@ -373,27 +373,58 @@ function withShopBridge(result: ShopBridgeResult) {
|
||||
api.shop.mockResolvedValue(result)
|
||||
}
|
||||
|
||||
it('京麦登录的不是勾选商品的店铺时不建单,并点名两家店', async () => {
|
||||
function crossShopProducts() {
|
||||
api.products.mockResolvedValue({
|
||||
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
|
||||
items: [{ id: 23, title: '示例商品', shopId: '148191738', shopName: '汽车用品数据库店' }], total: 1,
|
||||
})
|
||||
withShopBridge({ success: true, shopId: '165515933', shopName: '花屿巷旗舰店' })
|
||||
}
|
||||
|
||||
it('协议 3 的本机遇跨店只给升级提示,一条都不建单', async () => {
|
||||
crossShopProducts()
|
||||
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
|
||||
api.protocol.mockResolvedValue(3)
|
||||
const page = await mountPage()
|
||||
await page.get('.target-brand-input').setValue('示例品牌')
|
||||
await page.get<HTMLInputElement>('.product-check').setValue(true)
|
||||
// 勾选后不检测:按钮仍可点(未检测不拦),点下去才开始核对
|
||||
// 勾选后未检测:不拦,点下去才开始核对
|
||||
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
|
||||
await page.get('.collect-btn').trigger('click')
|
||||
await flushPromises()
|
||||
expect(api.shop).toHaveBeenCalledOnce()
|
||||
expect(api.create).not.toHaveBeenCalled()
|
||||
expect(api.enqueue).not.toHaveBeenCalled()
|
||||
expect(page.text()).toContain('京东店铺不匹配')
|
||||
expect(page.text()).toContain('家居日用数据库店')
|
||||
expect(page.text()).toContain('花屿巷旗舰店')
|
||||
expect(page.text()).toContain('升级')
|
||||
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
|
||||
})
|
||||
|
||||
it('协议 4 跨店:显形目标店与风险句,确认后才建单并带目标店', async () => {
|
||||
crossShopProducts()
|
||||
withShopBridge({ success: true, shopId: '228346061', shopName: '家居日用数据库店' })
|
||||
api.protocol.mockResolvedValue(4)
|
||||
const page = await mountPage()
|
||||
await page.get('.target-brand-input').setValue('示例品牌')
|
||||
await page.get<HTMLInputElement>('.product-check').setValue(true)
|
||||
await page.get('.shop-detect-btn').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(page.text()).toContain('跨店上架')
|
||||
expect(page.text()).toContain('目标店(跨店)')
|
||||
expect(page.text()).toContain('家居日用数据库店')
|
||||
expect(page.text()).not.toContain('京东店铺不匹配')
|
||||
// 二次确认是硬闸:没勾之前按钮禁用
|
||||
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(true)
|
||||
await page.get<HTMLInputElement>('.shop-cross-confirm input').setValue(true)
|
||||
await flushPromises()
|
||||
expect(page.get<HTMLButtonElement>('.collect-btn').element.disabled).toBe(false)
|
||||
|
||||
await page.get('.collect-btn').trigger('click')
|
||||
await flushPromises()
|
||||
expect(api.shop).toHaveBeenCalledOnce() // 已检测过,不再重复起浏览器
|
||||
expect(api.create).toHaveBeenCalledExactlyOnceWith(12, [23], { mode: 'none' }, '示例品牌',
|
||||
{ shopId: '228346061', shopName: '家居日用数据库店' })
|
||||
expect(api.enqueue).toHaveBeenCalledOnce()
|
||||
})
|
||||
|
||||
it('京麦与来源店铺一致时照常建单', async () => {
|
||||
api.products.mockResolvedValue({
|
||||
items: [{ id: 23, title: '示例商品', shopId: '228346061', shopName: '家居日用数据库店' }], total: 1,
|
||||
|
||||
Reference in New Issue
Block a user