|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | 2 | import { AVAILABLE_ROLES, getAllRoleDefinitions, getRoleDefinition } from './roles.js' |
3 | | -import type { Roles } from './user.js' |
4 | 3 |
|
5 | 4 | describe('roles', () => { |
6 | 5 | describe('AVAILABLE_ROLES', () => { |
@@ -30,86 +29,25 @@ describe('roles', () => { |
30 | 29 | } |
31 | 30 | }) |
32 | 31 |
|
33 | | - it('should have correct metadata for admin role', () => { |
34 | | - expect(AVAILABLE_ROLES.admin).toEqual({ |
35 | | - displayName: 'Application Admin', |
36 | | - description: 'Full system access including user management and all settings', |
37 | | - }) |
38 | | - }) |
39 | | - |
40 | | - it('should have correct metadata for media-manager role', () => { |
41 | | - expect(AVAILABLE_ROLES['media-manager']).toEqual({ |
42 | | - displayName: 'Media Manager', |
43 | | - description: 'Can manage movies, series, and encoding tasks', |
44 | | - }) |
45 | | - }) |
46 | | - |
47 | | - it('should have correct metadata for viewer role', () => { |
48 | | - expect(AVAILABLE_ROLES.viewer).toEqual({ |
49 | | - displayName: 'Viewer', |
50 | | - description: 'Can browse and watch media content', |
51 | | - }) |
52 | | - }) |
53 | | - |
54 | | - it('should have correct metadata for iot-manager role', () => { |
55 | | - expect(AVAILABLE_ROLES['iot-manager']).toEqual({ |
56 | | - displayName: 'IoT Manager', |
57 | | - description: 'Can manage IoT devices and their settings', |
58 | | - }) |
| 32 | + it.each([ |
| 33 | + ['admin', 'Application Admin', 'Full system access including user management and all settings'], |
| 34 | + ['media-manager', 'Media Manager', 'Can manage movies, series, and encoding tasks'], |
| 35 | + ['viewer', 'Viewer', 'Can browse and watch media content'], |
| 36 | + ['iot-manager', 'IoT Manager', 'Can manage IoT devices and their settings'], |
| 37 | + ] as const)('should have correct metadata for %s role', (role, displayName, description) => { |
| 38 | + expect(AVAILABLE_ROLES[role]).toEqual({ displayName, description }) |
59 | 39 | }) |
60 | 40 | }) |
61 | 41 |
|
62 | 42 | describe('getRoleDefinition', () => { |
63 | | - it('should return correct definition for admin role', () => { |
64 | | - const definition = getRoleDefinition('admin') |
65 | | - |
66 | | - expect(definition).toEqual({ |
67 | | - name: 'admin', |
68 | | - displayName: 'Application Admin', |
69 | | - description: 'Full system access including user management and all settings', |
70 | | - }) |
71 | | - }) |
72 | | - |
73 | | - it('should return correct definition for media-manager role', () => { |
74 | | - const definition = getRoleDefinition('media-manager') |
75 | | - |
76 | | - expect(definition).toEqual({ |
77 | | - name: 'media-manager', |
78 | | - displayName: 'Media Manager', |
79 | | - description: 'Can manage movies, series, and encoding tasks', |
80 | | - }) |
81 | | - }) |
82 | | - |
83 | | - it('should return correct definition for viewer role', () => { |
84 | | - const definition = getRoleDefinition('viewer') |
85 | | - |
86 | | - expect(definition).toEqual({ |
87 | | - name: 'viewer', |
88 | | - displayName: 'Viewer', |
89 | | - description: 'Can browse and watch media content', |
90 | | - }) |
91 | | - }) |
92 | | - |
93 | | - it('should return correct definition for iot-manager role', () => { |
94 | | - const definition = getRoleDefinition('iot-manager') |
95 | | - |
96 | | - expect(definition).toEqual({ |
97 | | - name: 'iot-manager', |
98 | | - displayName: 'IoT Manager', |
99 | | - description: 'Can manage IoT devices and their settings', |
100 | | - }) |
101 | | - }) |
102 | | - |
103 | | - it('should include name, displayName, and description for each role', () => { |
104 | | - const roles: Array<Roles[number]> = ['admin', 'media-manager', 'viewer', 'iot-manager'] |
105 | | - |
106 | | - for (const roleName of roles) { |
107 | | - const definition = getRoleDefinition(roleName) |
108 | | - |
109 | | - expect(definition.name).toBe(roleName) |
110 | | - expect(definition.displayName).toBeDefined() |
111 | | - expect(definition.description).toBeDefined() |
112 | | - } |
| 43 | + it.each([ |
| 44 | + ['admin', 'Application Admin', 'Full system access including user management and all settings'], |
| 45 | + ['media-manager', 'Media Manager', 'Can manage movies, series, and encoding tasks'], |
| 46 | + ['viewer', 'Viewer', 'Can browse and watch media content'], |
| 47 | + ['iot-manager', 'IoT Manager', 'Can manage IoT devices and their settings'], |
| 48 | + ] as const)('should return correct definition for %s role', (name, displayName, description) => { |
| 49 | + const definition = getRoleDefinition(name) |
| 50 | + expect(definition).toEqual({ name, displayName, description }) |
113 | 51 | }) |
114 | 52 | }) |
115 | 53 |
|
|
0 commit comments