roleUtils.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {$roleUtils} from "~/services/rights/roleUtils";
  2. let roles:Array<string>, final_role:Array<string>
  3. beforeEach(() => {
  4. roles = [
  5. 'ROLE_BOOK_CONFIG_VIEW',
  6. 'ROLE_ROOM_CONFIG',
  7. 'ROLE_USER',
  8. 'ROLE_ADMIN',
  9. 'ROLE_ADMIN_CORE',
  10. 'ROLE_PLACE_VIEW',
  11. 'ROLE_ADMINISTRATIF_MANAGER_CORE',
  12. ];
  13. final_role = [
  14. 'ROLE_GENERAL-CONFIG_VIEW',
  15. 'ROLE_TAGG-ADVANCED',
  16. 'ROLE_ROOM',
  17. 'ROLE_USER_VIEW'
  18. ];
  19. });
  20. describe('isA()', ()=>{
  21. it('should have the profil of ADMINISTRATIF_MANAGER thanks to his roles', () => {
  22. expect($roleUtils.isA('ADMINISTRATIF_MANAGER', roles)).toBeTruthy();
  23. })
  24. it('should not have the profil of ADMINISTRATIF_MANAGER thanks to his roles', ()=>{
  25. expect($roleUtils.isA('TEACHER', roles)).toBeFalsy();
  26. })
  27. })
  28. describe('filterFunctionRoles()', ()=>{
  29. it('should filters roles to keep just roles without function', () => {
  30. let filter_roles = [
  31. 'ROLE_BOOK_CONFIG_VIEW',
  32. 'ROLE_ROOM_CONFIG',
  33. 'ROLE_USER',
  34. 'ROLE_PLACE_VIEW'
  35. ];
  36. expect($roleUtils.filterFunctionRoles(roles)).toStrictEqual(filter_roles);
  37. })
  38. })
  39. describe('transformUnderscoreToHyphenBeforeCompleteMigration()', ()=> {
  40. it('should transform underscore to hyphen only on role name', () =>{
  41. let roles_to_array = [
  42. 'ROLE_GENERAL_CONFIG_VIEW',
  43. 'ROLE_TAGG_ADVANCED',
  44. 'ROLE_ROOM',
  45. 'ROLE_USER_VIEW'
  46. ];
  47. expect($roleUtils.transformUnderscoreToHyphenBeforeCompleteMigration(roles_to_array)).toStrictEqual(final_role);
  48. })
  49. })
  50. describe('transformRoleToAbilities()', ()=> {
  51. it('should convert Role to Abilities', () => {
  52. let abilities_to_have = [
  53. {action: 'read', subject: 'general-config'},
  54. {action: 'manage', subject: 'tagg-advanced'},
  55. {action: 'manage', subject: 'room'},
  56. {action: 'read', subject: 'user'}
  57. ]
  58. expect($roleUtils.transformRoleToAbilities(final_role)).toStrictEqual(abilities_to_have);
  59. })
  60. })