76 lines
3.6 KiB
TypeScript
76 lines
3.6 KiB
TypeScript
// role-menu-matrix.spec.ts S3·FE-6:五角色×全菜单权限矩阵走查(自动化快照)。
|
||
// 预期矩阵为**人工确认后的固化表**(非 routes.ts 同源推导)——任何人改动路由
|
||
// roles 都会在此暴露,走查语义=矩阵变更必须显式过目(与后端 casbin 五角色门对齐)。
|
||
// 语义基准:资金/通道/结算页=admin/ops;service=运营执行;group/customer=业务
|
||
// 与记录自助,不见平台资金信息(与后端 statsIsPlatform/ordersList/profit 平台门一致)。
|
||
import { describe, expect, it } from 'vitest'
|
||
import { accessibleRoutes } from '@/router/guard'
|
||
|
||
type Roles = 'admin' | 'ops' | 'service' | 'group' | 'customer'
|
||
const ALL: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
|
||
|
||
/** 预期矩阵:菜单 name → 允许角色(S3 固化,含 FE-D34 利润分析)。 */
|
||
const MATRIX: Record<string, Roles[]> = {
|
||
home: ALL,
|
||
notice: ['admin', 'ops', 'service', 'group'],
|
||
'account-list': ['admin', 'ops'],
|
||
audit: ['admin', 'ops', 'service'],
|
||
'sms-home': ALL, 'sms-batch': ALL, 'sms-personal': ALL, 'sms-timer': ALL,
|
||
'sms-result': ALL, 'sms-template': ALL, 'sms-downlink-detail': ALL,
|
||
video: ['admin', 'ops'], csp: ['admin', 'ops'], nullfilter: ['admin', 'ops'], shortlink: ['admin', 'ops'],
|
||
'record-down': ALL, 'record-up': ALL,
|
||
'record-repush': ['admin', 'ops', 'service'],
|
||
channel: ['admin', 'ops'], 'channel-upstream': ['admin', 'ops'], 'channel-group': ['admin', 'ops'],
|
||
policy: ['admin', 'ops'], 'policy-route': ['admin', 'ops'], 'policy-report': ['admin', 'ops'],
|
||
contacts: ALL,
|
||
'stats-user': ['admin', 'ops', 'service'], 'stats-channel': ['admin', 'ops'],
|
||
'stats-profit': ['admin', 'ops', 'service'], settle: ['admin', 'ops'],
|
||
'ops-callback': ['admin', 'ops'],
|
||
logs: ['admin', 'ops', 'service'], system: ['admin'], faq: ALL,
|
||
// Issue#4 发布日志:平台更新公告,面向全体用户(同 faq 口径,用户拍板)。
|
||
'system-release': ALL,
|
||
}
|
||
|
||
/** 实测:某角色经守卫过滤后的可见菜单集合。 */
|
||
function visibleMenus(role: Roles): Set<string> {
|
||
return new Set(
|
||
accessibleRoutes([role])
|
||
.flatMap((r) => r.children ?? [])
|
||
.filter((c) => c.meta?.menu)
|
||
.map((c) => String(c.name)),
|
||
)
|
||
}
|
||
|
||
describe('S3·FE-6 五角色×全菜单权限矩阵', () => {
|
||
const roles: Roles[] = ['admin', 'ops', 'service', 'group', 'customer']
|
||
|
||
it.each(roles)('角色 %s 可见菜单与矩阵一致', (role) => {
|
||
const visible = visibleMenus(role)
|
||
for (const [name, allow] of Object.entries(MATRIX)) {
|
||
const want = allow.includes(role)
|
||
expect(visible.has(name), `${role} × ${name}:期望${want ? '可见' : '不可见'}`).toBe(want)
|
||
}
|
||
})
|
||
|
||
it('矩阵覆盖全部菜单项(新增菜单未登记矩阵=本测试红,走查强制过目)', () => {
|
||
const adminVisible = visibleMenus('admin')
|
||
for (const name of adminVisible) expect(MATRIX[name], `菜单 ${name} 未登记矩阵`).toBeDefined()
|
||
expect(adminVisible.size).toBe(Object.keys(MATRIX).length)
|
||
})
|
||
|
||
it('资金与平台配置页对 group/customer 关闭(语义抽样:settle/stats-profit/channel/system)', () => {
|
||
for (const role of ['group', 'customer'] as Roles[]) {
|
||
const visible = visibleMenus(role)
|
||
for (const denied of ['settle', 'stats-profit', 'stats-channel', 'channel', 'channel-upstream', 'system', 'account-list', 'audit']) {
|
||
expect(visible.has(denied), `${role} 不应见 ${denied}`).toBe(false)
|
||
}
|
||
}
|
||
})
|
||
|
||
it('system 配置仅 admin', () => {
|
||
for (const role of ['ops', 'service', 'group', 'customer'] as Roles[]) {
|
||
expect(visibleMenus(role).has('system')).toBe(false)
|
||
}
|
||
})
|
||
})
|