import assert from 'node:assert/strict' import test from 'node:test' import { existsSync, readFileSync } from 'node:fs' import { join } from 'node:path' import { filterJdToolsByPermission, JD_GROUP_COLUMN_KEY, JD_TOOLS, JD_TOOL_MAP, } from '../src/pages/jd/tool-catalog.ts' /** 京东一级入口(v1.5):首页「京东」→ 京东工作台两个菜单(获取店铺数据 / 商品上架占位)。 */ const ROOT = process.cwd() function read(relativePath: string): string { const path = join(ROOT, relativePath) assert.ok(existsSync(path), `文件缺失:${path}`) return readFileSync(path, 'utf8') } test('京东工作台只有两个菜单:获取店铺数据 + 商品上架', () => { assert.equal(JD_TOOLS.length, 2, '京东工作台菜单数应为 2') const names = JD_TOOLS.map((tool) => tool.name) assert.deepEqual(names, ['获取店铺数据', '商品上架']) assert.equal(new Set(JD_TOOLS.map((tool) => tool.id)).size, 2, '工具 id 不应重复') assert.ok(JD_TOOL_MAP.get('jd-collect'), 'JD_TOOL_MAP 应按 id 命中获取店铺数据') }) test('获取店铺数据指向采集页,商品上架已转正式挂 /jd-publish(v1.5 Phase 4)', () => { const collect = JD_TOOLS.find((tool) => tool.id === 'jd-collect') const publish = JD_TOOLS.find((tool) => tool.id === 'jd-publish') assert.equal(collect?.href, '/jd-collect', '获取店铺数据应指向 /jd-collect') assert.equal(publish?.href, '/jd-publish', '商品上架已转正式:指向 /jd-publish(占位态已随 v1.5 Phase 4 下线)') }) test('路由器注册京东工作台与采集页', () => { const router = read('src/router/index.ts') assert.ok(router.includes("path: '/jd-console'"), 'router 缺 /jd-console') assert.ok(router.includes('JdConsolePage.vue'), 'router 未指向 JdConsolePage') assert.ok(router.includes("path: '/jd-collect'"), 'router 缺 /jd-collect') assert.ok(router.includes("path: '/jd-publish'"), 'router 缺 /jd-publish(v1.5 Phase 4 转正式)') }) test('首页京东入口与亚马逊/视频并列', () => { const home = read('src/pages/home/DesktopHomePage.vue') assert.ok(home.includes('jd-console.html'), '首页京东入口未指向京东工作台') assert.ok(/>京东 { const page = read('src/pages/jd/JdCollectTab.vue') // 进度真源仍是服务端:改版后走批量进度轮询(useLiveTaskBoard),不再有单任务进度条 assert.ok(page.includes('fetchJdCollectTaskProgressBatch'), '采集页必须经 useLiveTaskBoard 轮询服务端批量进度(不拿本地内存数充进度)') assert.ok(page.includes('file-progress') || page.includes('progress: showProgress'), '采集页任务卡片必须带进度条(照外观专利面板形状)') assert.ok(page.includes('一键获取店铺数据'), '主按钮应是一键获取') assert.ok(page.includes('jd-shop-collect-run'), '建单后必须推送本机客户端队列') assert.ok(page.includes('TaskCenterPanel'), '改版后右侧必须是共享任务面板(含历史任务层)') }) /* ===== V209 菜单权限:permissionKeys 与后端 app 菜单逐字对撞 + 过滤判据 ===== */ test('两张卡片都声明 permissionKeys 且与 V209 迁移 column_key 逐字一致', () => { // 跨仓对撞(后管 company-menu-route.test.ts 同族判据):迁移插的 app 菜单键与前端 // permissionKeys 任何一侧改名而另一侧不动 ⇒ 这里红,而不是线上静默"勾了不显示"。 const sqlPath = join(ROOT, '..', 'backend-java', 'src', 'main', 'resources', 'db', 'V209__jd_app_menu.sql') assert.ok(existsSync(sqlPath), `迁移缺失:${sqlPath}(V209 与前端权限键必须同窗改动)`) const sql = readFileSync(sqlPath, 'utf8') const frontendKeys = new Set([JD_GROUP_COLUMN_KEY, ...JD_TOOLS.flatMap((tool) => tool.permissionKeys)]) for (const key of frontendKeys) { assert.ok(sql.includes(`'${key}'`), `V209 迁移缺 column_key:${key}`) } for (const route of ['jd-tools', 'jd-collect', 'jd-publish']) { assert.ok(sql.includes(`'${route}'`), `V209 迁移缺 route_path:${route}`) } for (const tool of JD_TOOLS) { assert.ok(tool.permissionKeys.length > 0, `卡片 ${tool.id} 必须声明 permissionKeys`) } }) test('按菜单权限过滤京东卡片(与亚马逊 filterGroupsByPermission 同形判据)', () => { // 空权限集 ⇒ 全隐藏 assert.deepEqual(filterJdToolsByPermission(JD_TOOLS, []), []) // 组键命中 ⇒ 整组放行(V209 预授权授的就是组行) assert.equal(filterJdToolsByPermission(JD_TOOLS, ['jd_tools']).length, 2) // 只授采集 ⇒ 只剩采集卡 const collectOnly = filterJdToolsByPermission(JD_TOOLS, ['jd-collect']) assert.deepEqual(collectOnly.map((tool) => tool.id), ['jd-collect']) // 只授上架 ⇒ 只剩上架卡(占位卡转正前同样受控) const publishOnly = filterJdToolsByPermission(JD_TOOLS, ['jd-publish']) assert.deepEqual(publishOnly.map((tool) => tool.id), ['jd-publish']) // 大小写/空白归一(亚马逊侧同款 normalize:trim + lowercase) assert.equal(filterJdToolsByPermission(JD_TOOLS, [' JD_TOOLS ']).length, 2) // 无关键不放行任何卡片 assert.deepEqual(filterJdToolsByPermission(JD_TOOLS, ['collect-data', 'wb']), []) })