| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import {$roleUtils} from "~/services/rights/roleUtils";
- let roles:Array<string>, final_role:Array<string>
- beforeEach(() => {
- roles = [
- 'ROLE_BOOK_CONFIG_VIEW',
- 'ROLE_ROOM_CONFIG',
- 'ROLE_USER',
- 'ROLE_ADMIN',
- 'ROLE_ADMIN_CORE',
- 'ROLE_PLACE_VIEW',
- 'ROLE_ADMINISTRATIF_MANAGER_CORE',
- ];
- final_role = [
- 'ROLE_GENERAL-CONFIG_VIEW',
- 'ROLE_TAGG-ADVANCED',
- 'ROLE_ROOM',
- 'ROLE_USER_VIEW'
- ];
- });
- describe('isA()', ()=>{
- it('should have the profil of ADMINISTRATIF_MANAGER thanks to his roles', () => {
- expect($roleUtils.isA('ADMINISTRATIF_MANAGER', roles)).toBeTruthy();
- })
- it('should not have the profil of ADMINISTRATIF_MANAGER thanks to his roles', ()=>{
- expect($roleUtils.isA('TEACHER', roles)).toBeFalsy();
- })
- })
- describe('filterFunctionRoles()', ()=>{
- it('should filters roles to keep just roles without function', () => {
- let filter_roles = [
- 'ROLE_BOOK_CONFIG_VIEW',
- 'ROLE_ROOM_CONFIG',
- 'ROLE_USER',
- 'ROLE_PLACE_VIEW'
- ];
- expect($roleUtils.filterFunctionRoles(roles)).toStrictEqual(filter_roles);
- })
- })
- describe('transformUnderscoreToHyphenBeforeCompleteMigration()', ()=> {
- it('should transform underscore to hyphen only on role name', () =>{
- let roles_to_array = [
- 'ROLE_GENERAL_CONFIG_VIEW',
- 'ROLE_TAGG_ADVANCED',
- 'ROLE_ROOM',
- 'ROLE_USER_VIEW'
- ];
- expect($roleUtils.transformUnderscoreToHyphenBeforeCompleteMigration(roles_to_array)).toStrictEqual(final_role);
- })
- })
- describe('transformRoleToAbilities()', ()=> {
- it('should convert Role to Abilities', () => {
- let abilities_to_have = [
- {action: 'read', subject: 'general-config'},
- {action: 'manage', subject: 'tagg-advanced'},
- {action: 'manage', subject: 'room'},
- {action: 'read', subject: 'user'}
- ]
- expect($roleUtils.transformRoleToAbilities(final_role)).toStrictEqual(abilities_to_have);
- })
- })
|