Files
crawler-plugin/frontend-vue/tests/jd-publish-shop.test.ts
T
huangzd1997 10dec12ec0 refactor(前端): 前后台界面小字全面精简——删技术ID括号/页头操作提示条/机制解释句(2026-11-28 客户口径「这些小字都不需要多余,还有shopId啥的…除了必须要的比如任务ID密钥,其他精简一些」)
用户端 frontend-vue:
- jd-publish-shop.ts:shopLabel 只出店名(缺名兜底「店铺 N」),跨店/多店琥珀文案压成一两句,判据逻辑零改动
- JdPublishTab:删工具头/分类解释/品牌句后半,默认店铺/选品/collect-hint/中断回执/加价规则各压一句
- JdCollectTab:删工具头 desc、分类机制句、断点游标行,「页面筛选未生效兜底翻页中」从任务卡撤下
- jd-on-shelf 空态一句、JdConsolePage hero-sub 整段删(含过时的「正在建设中」)
- 品牌 10 个 tab:输入/筛选/加载长句压一句或删,任务卡删「结果ID/店铺ID/平台」技术行(店名已显形)
- 保留:错误出口、额度「当前在架X/Y」、GROUPS_EMPTY 空态动作句、检测按钮与店铺显形

后管 admin-frontend-vue:
- 每页顶部「当前页面操作提示」条整条下线(删 OperationGuide.vue+operation-guides.ts)
- 撞款/任务中心/关键词用量/密钥用量/客户端包/教程/软件版本/数字人/菜单/店铺密钥/登录页逐页删说明小字(保留:踢线警示、「留空=永不过期」、「不要带v前缀」、「仅支持.zip」、草稿需手动发布、已授权人数、安全提示)
- 编辑/建号弹窗 label 括号收短;代理弹窗/设备日志(删 pywebview/kk-browser 进程名)/密钥 pill title/授权弹窗 dim/品牌门控空态收短

测试同步(16 支改反钉或同步断言,全部当场绿):
- align-operation-guide 整份重写为反钉(组件与文案表不得回流)
- source-pin 台账 task-center-board 条目手工点名 7/3/5→24/14/28:旧值是切分器把正则字面量内裸引号当字符串开关吞掉 18 支用例的误量(stripNonCode 不识别 regex literal),本次改写恰好移除该文件最后两处带引号正则后测出真值;真实用例数反而 25→24(删 1 支 guide 用例),非真实增长

门禁:后管 node --test 1965/1965+vitest 253/253+vue-tsc rc=0;用户端 node 1150/mount 149/vue-tsc rc=0;ops 快检 --fast overall=pass(后端9.5/后管8.8/客户端9.8/用户端9.6)。本窗不发版;app_client/jar/后端零改动。
2026-11-28 01:14:51 +08:00

222 lines
12 KiB
TypeScript
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.
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import test from 'node:test'
import {
canUseJdPublish,
JD_PUBLISH_DENIED_TEXT,
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,
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 覆盖。
*/
const ROOT = process.cwd()
function read(relativePath: string, what: string): string {
const path = join(ROOT, relativePath)
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
return readFileSync(path, 'utf8')
}
// ---------------------------------------------------------------- 店铺身份判据
test('来源店铺按 id 去重、同名单店归一、空值全部丢弃', () => {
const refs = sourceShopRefs([
{ shopId: ' 228346061 ', shopName: ' 家居日用数据库店 ' },
{ shopId: '228346061', shopName: '家居日用数据库店' },
{ shopId: '', shopName: '家居日用数据库店' },
{ shopName: '花屿巷旗舰店' },
{ shopId: null, shopName: ' ' },
{},
])
assert.deepEqual(refs, [
{ shopId: '228346061', shopName: '家居日用数据库店' },
{ shopName: '花屿巷旗舰店' },
], '同一家店不同行只算一家;店名回退 id 时不能把空 id 当身份')
})
test('同一家店两种形状(只有 id / 只有店名)在来源集里能归一', () => {
// id 口径优先:一行有 id 一行只有名字时,页面无法确定同店,按两家报出(多店整单走跨店新增)
const refs = sourceShopRefs([{ shopId: '1' }, { shopName: '某店' }])
assert.equal(refs.length, 2)
})
test('店铺标签:只出店名(2026-11-28 精简口径 shopId 不上屏),缺名报「店铺 <id>」,全空=未记录店铺', () => {
assert.equal(shopLabel({ shopId: '1', shopName: '某店' }), '某店')
assert.ok(!shopLabel({ shopId: '1', shopName: '某店' }).includes('shopId='), '店名上屏时不许带 shopId 技术前缀')
assert.equal(shopLabel({ shopName: '某店' }), '某店')
assert.equal(shopLabel({ shopId: '1' }), '店铺 1')
assert.equal(shopLabel(null), '未记录店铺')
assert.equal(normalizeShopRef({ shopId: ' ' }), null)
})
test('跨店文案:点名来源店与目标店、说明会新建商品要过审、要求目标店已授权类目,不写「稍后重试」', () => {
const message = crossShopMessage(
{ shopId: '148191738', shopName: '汽车用品数据库店' },
{ shopId: '228346061', shopName: '家居日用数据库店' },
)
assert.ok(message.startsWith('跨店上架'))
assert.ok(message.includes('汽车用品数据库店') && message.includes('家居日用数据库店'),
'来源店与目标店(京麦当前登录)都要点名')
assert.ok(!message.includes('148191738') && !message.includes('shopId='),
'2026-11-28 精简口径:技术 id 不上屏')
assert.ok(message.includes('新建'), '必须说清跨店是在目标店新建商品')
assert.ok(message.includes('授权'), '必须点名目标店类目授权这个硬前提')
assert.ok(message.includes('审核'), '必须说清要过京东审核')
assert.ok(!message.includes('稍后重试'), '确定性失败不允许写「稍后重试」')
})
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 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('跨店档默认拦(本机协议不够),显式允许后才放行;提示换升级文案', () => {
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('协议门槛常量与服务端/客户端代次同档(品牌 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, 'cross')
assert.equal(evaluateShopGuard([{ shopId: '1' }], { shopName: '某店' }).state, 'undetected')
})
// 2026-11-26 晚客户口径「去掉一次只能发一家店的约束」:多店不再整单拦死。
test('多店未检测京麦:拦并点名两家店与「先检测」动作(没有目标店服务端也会拒)', () => {
const guard = evaluateShopGuard([{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }], null)
assert.equal(guard.state, 'multi')
if (guard.state === 'multi') assert.equal(guard.target, null)
assert.ok(shopGuardBlocks(guard))
assert.ok(shopGuardMessage(guard).includes('甲店') && shopGuardMessage(guard).includes('乙店'))
assert.ok(shopGuardMessage(guard).includes('检测'))
assert.ok(!shopGuardMessage(guard).includes('分开勾选'), '旧「按店分开勾选」口径不得复活')
})
test('多店已检测京麦:整单按跨店新增放行(协议 ≥4+人工确认),文案点名各来源店与目标店', () => {
const guard = evaluateShopGuard(
[{ shopId: '1', shopName: '甲店' }, { shopId: '2', shopName: '乙店' }],
{ shopId: '3', shopName: '丙店' },
)
assert.equal(guard.state, 'multi')
if (guard.state === 'multi') {
assert.deepEqual(guard.target, { shopId: '3', shopName: '丙店' }, '目标店=京麦当前登录店')
assert.ok(guard.message.includes('甲店') && guard.message.includes('乙店') && guard.message.includes('丙店'))
assert.ok(guard.message.includes('新建'), '必须说清多店是在目标店新建上架(精简后统一用「新建」)')
assert.ok(guard.message.includes('授权') && guard.message.includes('审核'))
assert.ok(!guard.message.includes('shopId='), '精简口径:多店文案不拼技术 id')
}
assert.ok(shopGuardBlocks(guard), '协议 < 4 仍拦:老客户端没有新增商品路径')
assert.equal(shopGuardMessage(guard), CROSS_UPGRADE_NOTICE)
assert.ok(!shopGuardBlocks(guard, true), '协议 ≥4 放行(建单前还要页面二次确认,那是页面层硬闸)')
assert.equal(shopGuardMessage(guard, true), '')
})
// ---------------------------------------------------------------- 菜单权限判据
test('权限判据:组键 jd_tools 或子键 jd-publish 命中即放行(大小写/空白归一)', () => {
assert.ok(canUseJdPublish(['jd_tools']))
assert.ok(canUseJdPublish([' JD-PUBLISH ']))
assert.ok(!canUseJdPublish(['jd-collect']), '只授「获取店铺数据」不包含「商品上架」')
assert.ok(!canUseJdPublish([]))
assert.ok(!canUseJdPublish(['jd_tools_extra']), '前缀相近不算命中')
})
test('路由判据三态:拿到空键集=denied,拿不到键集(接口失败)=unknown 放行', () => {
assert.equal(resolveJdPublishAccess(['jd-collect']), 'denied')
assert.equal(resolveJdPublishAccess(null), 'unknown')
assert.equal(resolveJdPublishAccess(['jd-publish']), 'allowed')
assert.ok(JD_PUBLISH_DENIED_TEXT.includes('菜单权限'))
assert.ok(JD_PUBLISH_DENIED_TEXT.includes('商品上架'))
})
// ---------------------------------------------------------------- 源码绊线(接线不许漏)
test('上架页显形来源店铺与京麦当前店铺,并在建单前核对', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(tab.includes('get_jd_shop_info'), '页面必须调桥 get_jd_shop_info 现拉京麦当前店铺')
assert.ok(tab.includes('ensureShopChecked'), '建单前必须走店铺核对(strong block)')
assert.ok(tab.includes('shopGuardBlocks'), '不匹配/跨店必须禁掉上架按钮')
assert.ok(tab.includes('evaluateShopGuard(selectedProductRows'),
'来源店铺判据必须吃本分类全部商品行(2026-11-26 晚选分类=整分类上架,不再只吃被勾选的行)')
const createAt = tab.indexOf('createJdPublishTask(')
const checkAt = tab.indexOf('await ensureShopChecked()')
assert.ok(checkAt > 0 && createAt > checkAt, '核对必须早于建单')
})
test('上架页不得自己拼店铺身份(只用勾选商品快照 + 桥结果)', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '商品上架页')
assert.ok(!/shopId\s*=\s*['"]\d+/.test(tab), '页面不得写死任何 shopId')
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'), '路由必须用统一判据模块')
assert.ok(/path: '\/jd-publish'[\s\S]{0,200}?beforeEnter:/.test(router), '/jd-publish 缺 beforeEnter 守卫')
assert.ok(router.includes('getCurrentUserAppColumnKeys'), '守卫必须读当前用户 app 列权限')
assert.ok(router.includes("path: '/jd-console'"), '没权限时回工作台(那里只显示有权限的卡片)')
})
test('桥类型声明 get_jd_shop_info(老客户端按缺方法置灰)', () => {
const bridge = read('src/shared/bridges/pywebview.ts', 'pywebview.ts')
assert.ok(bridge.includes('get_jd_shop_info?:'), 'PywebviewApi 缺 get_jd_shop_info 声明')
})