yaml.spec.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import Yaml from '~/services/serializer/denormalizer/yaml'
  2. import { DENORMALIZER_TYPE } from '~/types/enums'
  3. describe('support()', () => {
  4. it('should support model yaml type', () => {
  5. expect(Yaml.support(DENORMALIZER_TYPE.YAML)).toBeTruthy()
  6. })
  7. it('should not support hydra type', () => {
  8. expect(Yaml.support(DENORMALIZER_TYPE.HYDRA)).toBeFalsy()
  9. })
  10. })
  11. describe('denormalize()', () => {
  12. it('should throw an error if file doesnt exist', () => {
  13. const path = './tests/unit/fixture/files/not_exist_file.yaml'
  14. expect(() => Yaml.denormalize({ path })).toThrowError()
  15. })
  16. it('should parse a Yaml file and return a JSON Object', () => {
  17. const path = './tests/unit/fixture/files/test.yaml'
  18. expect(Yaml.denormalize({ path })).toStrictEqual({
  19. abilities: {
  20. accesses: {
  21. action: 'display',
  22. services: {
  23. access: [
  24. {
  25. function: 'hasAbility',
  26. parameters: [{
  27. action: 'read',
  28. subject: 'user'
  29. }]
  30. }
  31. ],
  32. organization: [
  33. {
  34. function: 'hasModule',
  35. parameters: [
  36. 'Users'
  37. ]
  38. }
  39. ]
  40. }
  41. },
  42. student_registration: {
  43. action: 'display',
  44. services: {
  45. access: [
  46. {
  47. function: 'hasAbility',
  48. parameters: [{
  49. action: 'read',
  50. subject: 'student-registration'
  51. }]
  52. }
  53. ],
  54. organization: [
  55. {
  56. function: 'hasModule',
  57. parameters: [
  58. 'UsersSchool'
  59. ]
  60. }
  61. ]
  62. }
  63. }
  64. }
  65. })
  66. })
  67. })