gongxiangp2/lib/__tests__/brand-center-access-policy.test.ts

53 lines
2.7 KiB
TypeScript

import {
hasBrandCenterAccess,
isBrandCenterOrganizationPath,
isBrandCenterRestrictedPath,
shouldRedirectToStandaloneMaterialLibrary,
} from '@/lib/brand-center-access-policy'
describe('brand center access policy', () => {
test('只把路径中的精确品牌中心节点视为品牌中心范围', () => {
expect(isBrandCenterOrganizationPath('江苏简尚品牌管理有限公司/品牌中心/品牌创意A部')).toBe(true)
expect(isBrandCenterOrganizationPath('江苏简尚品牌管理有限公司/龙晨品牌中心')).toBe(false)
expect(isBrandCenterOrganizationPath('江苏简尚品牌管理有限公司/运营中心A')).toBe(false)
})
test('品牌中心任一任职路径可进入,明确离职则不可进入', () => {
expect(hasBrandCenterAccess({
role: 'USER',
departmentPaths: ['集团/摄影中心', '集团/品牌中心/综合支持部'],
})).toBe(true)
expect(hasBrandCenterAccess({
role: 'USER',
employmentState: 'RESIGNED',
departmentPaths: ['集团/品牌中心'],
})).toBe(false)
})
test('系统管理员保留维护通行,外部门管理员不自动获得品牌中心权限', () => {
expect(hasBrandCenterAccess({ role: 'SYSTEM_ADMIN', departmentPaths: [] })).toBe(true)
expect(hasBrandCenterAccess({ role: 'USER', isSuperAdmin: true, departmentPaths: [] })).toBe(true)
expect(hasBrandCenterAccess({ role: 'DEPT_ADMIN', departmentPaths: ['集团/运营中心A'] })).toBe(false)
})
test('品牌中心与管理工作面统一受组织范围门禁,素材工作流保持可用', () => {
expect(isBrandCenterRestrictedPath('/')).toBe(true)
expect(isBrandCenterRestrictedPath('/workspaces/dashboard/core-metrics')).toBe(true)
expect(isBrandCenterRestrictedPath('/admin')).toBe(true)
expect(isBrandCenterRestrictedPath('/organization')).toBe(true)
expect(isBrandCenterRestrictedPath('/performance-survey/monthly')).toBe(true)
expect(isBrandCenterRestrictedPath('/work-review')).toBe(true)
expect(isBrandCenterRestrictedPath('/teacher/templates')).toBe(true)
expect(isBrandCenterRestrictedPath('/assets/material-library')).toBe(false)
expect(isBrandCenterRestrictedPath('/materials')).toBe(false)
expect(isBrandCenterRestrictedPath('/profile')).toBe(false)
})
test('外部人员访问旧素材库或品牌中心工作面时统一进入正式素材库', () => {
expect(shouldRedirectToStandaloneMaterialLibrary('/materials', false)).toBe(true)
expect(shouldRedirectToStandaloneMaterialLibrary('/workspaces/dashboard/core-metrics', false)).toBe(true)
expect(shouldRedirectToStandaloneMaterialLibrary('/assets/material-library', false)).toBe(false)
expect(shouldRedirectToStandaloneMaterialLibrary('/materials', true)).toBe(false)
})
})