yaml.spec.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. const yaml = new Yaml()
  15. expect(() => yaml.denormalize({path :path})).toThrow()
  16. })
  17. it('should parse a Yaml file and return a JSON Object', () => {
  18. const path = './tests/unit/fixture/files/test.yaml'
  19. const yaml = new Yaml()
  20. expect(yaml.denormalize({path :path})).toStrictEqual({
  21. "abilities": {
  22. "accesses": {
  23. "action": "display",
  24. "services": {
  25. "access": [
  26. {
  27. "function": "hasAbility",
  28. "parameters": [{
  29. "action": "read",
  30. "subject": "user"
  31. }]
  32. }
  33. ],
  34. "organization": [
  35. {
  36. "function": "hasModule",
  37. "parameters": [
  38. "Users"
  39. ]
  40. }
  41. ]
  42. }
  43. },
  44. "student_registration": {
  45. "action": "display",
  46. "services": {
  47. "access": [
  48. {
  49. "function": "hasAbility",
  50. "parameters": [{
  51. "action": "read",
  52. "subject": "student-registration"
  53. }]
  54. }
  55. ],
  56. "organization": [
  57. {
  58. "function": "hasModule",
  59. "parameters": [
  60. "UsersSchool"
  61. ]
  62. }
  63. ]
  64. }
  65. }
  66. }
  67. });
  68. });
  69. })