wrap-spec-selectors.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { fromJS } from "immutable"
  2. import {
  3. definitions
  4. } from "corePlugins/oas3/spec-extensions/wrap-selectors"
  5. describe("oas3 plugin - spec extensions - wrapSelectors", function(){
  6. describe("definitions", function(){
  7. it("should return definitions by default", function () {
  8. // Given
  9. const spec = fromJS({
  10. openapi: "3.0.0",
  11. components: {
  12. schemas: {
  13. a: {
  14. type: "string"
  15. },
  16. b: {
  17. type: "string"
  18. }
  19. }
  20. }
  21. })
  22. const system = {
  23. getSystem: () => system,
  24. specSelectors: {
  25. specJson: () => spec,
  26. }
  27. }
  28. // When
  29. let res = definitions(() => null, system)(fromJS({
  30. json: spec
  31. }))
  32. // Then
  33. expect(res.toJS()).toEqual({
  34. a: {
  35. type: "string"
  36. },
  37. b: {
  38. type: "string"
  39. }
  40. })
  41. })
  42. it("should return an empty Map when missing definitions", function () {
  43. // Given
  44. const spec = fromJS({
  45. openapi: "3.0.0"
  46. })
  47. const system = {
  48. getSystem: () => system,
  49. specSelectors: {
  50. specJson: () => spec,
  51. }
  52. }
  53. // When
  54. let res = definitions(() => null, system)(fromJS({
  55. json: spec
  56. }))
  57. // Then
  58. expect(res.toJS()).toEqual({})
  59. })
  60. it("should return an empty Map when given non-object definitions", function () {
  61. // Given
  62. const spec = fromJS({
  63. openapi: "3.0.0",
  64. components: {
  65. schemas: "..."
  66. }
  67. })
  68. const system = {
  69. getSystem: () => system,
  70. specSelectors: {
  71. specJson: () => spec,
  72. }
  73. }
  74. // When
  75. let res = definitions(() => null, system)(fromJS({
  76. json: spec
  77. }))
  78. // Then
  79. expect(res.toJS()).toEqual({})
  80. })
  81. })
  82. })