refactor: 迁移roles单元测试到src目录
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { AdminRole } from '../admin.role';
|
||||
|
||||
describe('AdminRole', () => {
|
||||
it('should have admin credentials', () => {
|
||||
expect(AdminRole.name).toBe('admin');
|
||||
expect(AdminRole.displayName).toBe('超级管理员');
|
||||
expect(AdminRole.credentials.username).toBe('admin');
|
||||
expect(AdminRole.credentials.password).toBe('Test@123');
|
||||
});
|
||||
|
||||
it('should have all permissions', () => {
|
||||
expect(AdminRole.permissions).toContain('user:*');
|
||||
expect(AdminRole.permissions).toContain('role:*');
|
||||
expect(AdminRole.permissions).toContain('menu:*');
|
||||
expect(AdminRole.cannotAccess).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should be able to create all resources', () => {
|
||||
expect(AdminRole.expectedBehaviors.canCreate).toContain('user');
|
||||
expect(AdminRole.expectedBehaviors.canCreate).toContain('role');
|
||||
expect(AdminRole.expectedBehaviors.canCreate).toContain('menu');
|
||||
});
|
||||
});
|
||||
@@ -1,30 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import type { RoleDefinition } from '../base.role';
|
||||
|
||||
describe('RoleDefinition', () => {
|
||||
it('should define required role properties', () => {
|
||||
const role: RoleDefinition = {
|
||||
name: 'test',
|
||||
displayName: '测试角色',
|
||||
credentials: {
|
||||
username: 'testuser',
|
||||
password: 'Test@123'
|
||||
},
|
||||
permissions: ['test:read', 'test:write'],
|
||||
cannotAccess: ['/admin'],
|
||||
expectedBehaviors: {
|
||||
canCreate: ['test'],
|
||||
canRead: ['test'],
|
||||
canUpdate: ['test'],
|
||||
canDelete: []
|
||||
}
|
||||
};
|
||||
|
||||
expect(role.name).toBe('test');
|
||||
expect(role.displayName).toBe('测试角色');
|
||||
expect(role.credentials.username).toBe('testuser');
|
||||
expect(role.credentials.password).toBe('Test@123');
|
||||
expect(role.permissions).toHaveLength(2);
|
||||
expect(role.cannotAccess).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { RoleFactory } from '../role-factory';
|
||||
|
||||
describe('RoleFactory', () => {
|
||||
it('should get admin role', () => {
|
||||
const role = RoleFactory.getRole('admin');
|
||||
expect(role.name).toBe('admin');
|
||||
expect(role.credentials.username).toBe('admin');
|
||||
});
|
||||
|
||||
it('should get user role', () => {
|
||||
const role = RoleFactory.getRole('user');
|
||||
expect(role.name).toBe('user');
|
||||
expect(role.credentials.username).toBe('normaluser');
|
||||
});
|
||||
|
||||
it('should throw error for unknown role', () => {
|
||||
expect(() => RoleFactory.getRole('unknown')).toThrow("Role 'unknown' not found");
|
||||
});
|
||||
|
||||
it('should get all roles', () => {
|
||||
const roles = RoleFactory.getAllRoles();
|
||||
expect(roles).toHaveLength(3);
|
||||
expect(roles.map(r => r.name)).toContain('admin');
|
||||
expect(roles.map(r => r.name)).toContain('user');
|
||||
expect(roles.map(r => r.name)).toContain('test');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user