5 处逐字硬编码 profile?.account==='admin'||userId==='ADMIN'(Topbar/ModelerPage/NewFeatureShell/AiFeatureForm/DesignCenterPage)收口到 auth/token.ts 纯函数 isAdminProfile,口径不变。
顺带:5 个页面测试的 vi.mock('../auth/token') 从整模块替换改为 importOriginal 只覆盖 getProfile(不再 mock 纯函数,修复 mock 漏 isAdminProfile 致的 render 崩)。
验证:新增 token.test.ts 4 测试 + tsc -b 干净 + vitest 18 文件/77 测试全绿。见总览 §10 B4。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
24 lines
751 B
TypeScript
24 lines
751 B
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { isAdminProfile, type UserProfile } from './token';
|
|
|
|
const base: UserProfile = { userId: 'U1', account: 'user', name: '张三', roles: [] };
|
|
|
|
describe('isAdminProfile', () => {
|
|
it('account 为 admin 判为管理员', () => {
|
|
expect(isAdminProfile({ ...base, account: 'admin' })).toBe(true);
|
|
});
|
|
|
|
it('userId 为 ADMIN 判为管理员', () => {
|
|
expect(isAdminProfile({ ...base, userId: 'ADMIN' })).toBe(true);
|
|
});
|
|
|
|
it('普通用户(account/userId 均非管理员)判否', () => {
|
|
expect(isAdminProfile(base)).toBe(false);
|
|
});
|
|
|
|
it('null / undefined 判否', () => {
|
|
expect(isAdminProfile(null)).toBe(false);
|
|
expect(isAdminProfile(undefined)).toBe(false);
|
|
});
|
|
});
|