No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

135 líneas
3.0 KiB

  1. /* eslint-env mocha */
  2. import expect from "expect"
  3. import { fromJS } from "immutable"
  4. import { parameterValues, contentTypeValues, operationScheme } from "corePlugins/spec/selectors"
  5. describe("spec plugin - selectors", function(){
  6. describe("parameterValue", function(){
  7. it("should return Map({}) if no path found", function(){
  8. // Given
  9. const spec = fromJS({ })
  10. // When
  11. let paramValues = parameterValues(spec, ["/one", "get"])
  12. // Then
  13. expect(paramValues.toJS()).toEqual({})
  14. })
  15. it("should return a hash of [parameterName]: value", function(){
  16. // Given
  17. const spec = fromJS({
  18. resolved: {
  19. paths: {
  20. "/one": {
  21. get: {
  22. parameters: [
  23. { name: "one", value: 1},
  24. { name: "two", value: "duos"}
  25. ]
  26. }
  27. }
  28. }
  29. }
  30. })
  31. // When
  32. let paramValues = parameterValues(spec, ["/one", "get"])
  33. // Then
  34. expect(paramValues.toJS()).toEqual({
  35. one: 1,
  36. two: "duos"
  37. })
  38. })
  39. })
  40. describe("contentTypeValues", function(){
  41. it("should return { requestContentType, responseContentType } from an operation", function(){
  42. // Given
  43. let state = fromJS({
  44. resolved: {
  45. paths: {
  46. "/one": {
  47. get: {
  48. "consumes_value": "one",
  49. "produces_value": "two"
  50. }
  51. }
  52. }
  53. }
  54. })
  55. // When
  56. let contentTypes = contentTypeValues(state, [ "/one", "get" ])
  57. // Then
  58. expect(contentTypes.toJS()).toEqual({
  59. requestContentType: "one",
  60. responseContentType: "two"
  61. })
  62. })
  63. it("should be ok, if no operation found", function(){
  64. // Given
  65. let state = fromJS({ })
  66. // When
  67. let contentTypes = contentTypeValues(state, [ "/one", "get" ])
  68. // Then
  69. expect(contentTypes.toJS()).toEqual({
  70. requestContentType: undefined,
  71. responseContentType: undefined
  72. })
  73. })
  74. })
  75. describe("operationScheme", function(){
  76. it("should return the correct scheme for a remote spec that doesn't specify a scheme", function(){
  77. // Given
  78. let state = fromJS({
  79. url: "https://generator.swagger.io/api/swagger.json",
  80. resolved: {
  81. paths: {
  82. "/one": {
  83. get: {
  84. "consumes_value": "one",
  85. "produces_value": "two"
  86. }
  87. }
  88. }
  89. }
  90. })
  91. // When
  92. let scheme = operationScheme(state, ["/one"], "get")
  93. // Then
  94. expect(scheme).toEqual("https")
  95. })
  96. // it("should be ok, if no operation found", function(){
  97. // // Given
  98. // let state = fromJS({ })
  99. //
  100. // // When
  101. // let contentTypes = contentTypeValues(state, [ "/one", "get" ])
  102. // // Then
  103. // expect(contentTypes.toJS()).toEqual({
  104. // requestContentType: undefined,
  105. // responseContentType: undefined
  106. // })
  107. // })
  108. })
  109. })