abilitiesUtils.spec.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {$abilitiesUtils} from "~/services/rights/abilitiesUtils";
  2. test('test transformAbilitiesConfigToAbility', () => {
  3. const abilitiesConfig = {
  4. "accesses": {
  5. "action": "display",
  6. "services": {
  7. "access": [
  8. {
  9. "function": "hasAbility",
  10. "parameters": {
  11. "action": "read",
  12. "subject": "user"
  13. }
  14. }
  15. ],
  16. "organization": [
  17. {
  18. "function": "hasModule",
  19. "parameters": [
  20. "Users"
  21. ]
  22. }
  23. ]
  24. }
  25. },
  26. "student_registration": {
  27. "action": "display",
  28. "services": {
  29. "access": [
  30. {
  31. "function": "hasAbility",
  32. "parameters": {
  33. "action": "read",
  34. "subject": "student-registration"
  35. }
  36. }
  37. ],
  38. "organization": [
  39. {
  40. "function": "hasModule",
  41. "parameters": [
  42. "UsersSchool"
  43. ]
  44. }
  45. ]
  46. }
  47. }
  48. };
  49. const abilitiesUtils = $abilitiesUtils()
  50. let abilities_to_have = [
  51. {action: 'display', subject: 'accesses'},
  52. {action: 'display', subject: 'student_registration'}
  53. ]
  54. expect(abilitiesUtils.transformAbilitiesConfigToAbility(abilitiesConfig)).toStrictEqual(abilities_to_have);
  55. })