Files
crawler-plugin/admin-frontend-vue/tests/company-menu-route.test.ts
T
huangzd1997 23c1402a75 feat(brandgating): 品牌Gating库恢复独立菜单
V164 建菜单、V166 回滚后,按 2026-10-25 决定用 V174 恢复独立菜单,
不再作为「店铺数据重复检查」的第三页签;后端权限键同步改为 admin_brand_gating。
2026-10-25 21:53:51 +08:00

77 lines
3.9 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 { test } from 'node:test'
import assert from 'node:assert/strict'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { adminPages } from '../src/router/routes.ts'
/** V143 往 columns 表插了「公司管理」菜单。侧边栏/路由门禁/面包屑都按
* column_key → adminPages.menuKey 关联(menu-route-map.ts 用注册表算出的规范路径覆盖库里的
* route_path),所以真正的跨产物契约是「迁移插入的菜单 key 必须在注册表登记」。
* 少登记一条 = 菜单看得见、点进去 404,且权限门禁认不出这个 key。 */
const MIGRATION = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources', 'db',
'V143__company_and_users_company_id.sql')
const BRAND_GATING_MIGRATION = join(process.cwd(), '..', 'backend-java', 'src', 'main', 'resources', 'db',
'V174__restore_admin_brand_gating_menu.sql')
interface MigrationMenu {
name: string
columnKey: string
routePath: string
}
/** 从迁移里抓出插入的菜单行(name / column_key / route_path)。 */
function menusInsertedBy(sql: string): MigrationMenu[] {
const menus: MigrationMenu[] = []
const re = /SELECT\s+'([^']+)',\s*'([^']+)',\s*'admin',\s*'([^']+)'/g
let match: RegExpExecArray | null
while ((match = re.exec(sql))) {
menus.push({ name: match[1], columnKey: match[2], routePath: match[3] })
}
return menus
}
function migrationSql(): string {
assert.ok(existsSync(MIGRATION), `迁移文件读不到,护栏无法核对菜单登记: ${MIGRATION}`)
return readFileSync(MIGRATION, 'utf8')
}
test('V143 插入的菜单 key 都必须在路由注册表登记', () => {
const menus = menusInsertedBy(migrationSql())
// 解析自证:正则漏抓就会恒绿,这里用独立的 INSERT INTO columns 计数交叉核对
const insertCount = (migrationSql().match(/INSERT INTO `columns`/g) || []).length
assert.ok(menus.length > 0, '迁移里应当插入了后台菜单,一条都没解析出来说明正则失效')
assert.equal(menus.length, insertCount, `解析到 ${menus.length} 条,但迁移有 ${insertCount} 条 INSERT INTO columns`)
const registered = new Set(adminPages.map((page) => page.menuKey))
for (const menu of menus) {
assert.ok(registered.has(menu.columnKey),
`菜单 key "${menu.columnKey}"(${menu.name})未在 src/router/routes.ts 登记 menuKey`)
}
})
test('V143 的「公司管理」菜单落到已注册的公司管理页', () => {
const menus = menusInsertedBy(migrationSql())
const companies = menus.find((menu) => menu.columnKey === 'admin_companies')
assert.ok(companies, '迁移必须插入 admin_companies 菜单')
const page = adminPages.find((item) => item.menuKey === 'admin_companies')
assert.ok(page, 'routes.ts 必须有 admin_companies 页面')
assert.equal(page.path, companies.routePath, '库里的 route_path 应与注册表路径一致')
assert.equal(page.title, companies.name, '页面标题应与菜单名一致')
})
test('V174 恢复的「品牌Gating库」菜单 key 必须在路由注册表登记', () => {
const sql = readFileSync(BRAND_GATING_MIGRATION, 'utf8')
const menus = menusInsertedBy(sql)
const insertCount = (sql.match(/INSERT INTO `columns`/g) || []).length
assert.ok(menus.length > 0, 'V174 应当插入后台菜单,一条都没解析出来说明正则失效')
assert.equal(menus.length, insertCount, `解析到 ${menus.length} 条,但迁移有 ${insertCount} 条 INSERT INTO columns`)
const gating = menus.find((menu) => menu.columnKey === 'admin_brand_gating')
assert.ok(gating, 'V174 必须插入 admin_brand_gating 菜单')
const page = adminPages.find((item) => item.menuKey === 'admin_brand_gating')
assert.ok(page, 'routes.ts 必须有 admin_brand_gating 页面,否则菜单点进去 404')
assert.equal(page.title, gating.name, '页面标题应与菜单名一致')
assert.equal(page.companyScoped, false, 'Gating 库全平台共享,不参与公司 tab')
})