You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

spec-reducer.js 2.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* eslint-env mocha */
  2. import expect from "expect"
  3. import { fromJS } from "immutable"
  4. import reducer from "corePlugins/spec/reducers"
  5. describe("spec plugin - reducer", function(){
  6. describe("update operation value", function() {
  7. it("should update the operation at the specified key", () => {
  8. const updateOperationValue = reducer["spec_update_operation_value"]
  9. const state = fromJS({
  10. resolved: {
  11. "paths": {
  12. "/pet": {
  13. "post": {
  14. "description": "my operation"
  15. }
  16. }
  17. }
  18. }
  19. })
  20. let result = updateOperationValue(state, {
  21. payload: {
  22. path: ["/pet", "post"],
  23. value: "application/json",
  24. key: "consumes_value"
  25. }
  26. })
  27. let expectedResult = {
  28. resolved: {
  29. "paths": {
  30. "/pet": {
  31. "post": {
  32. "description": "my operation",
  33. "consumes_value": "application/json"
  34. }
  35. }
  36. }
  37. }
  38. }
  39. expect(result.toJS()).toEqual(expectedResult)
  40. })
  41. it("shouldn't throw an error if we try to update the consumes_value of a null operation", () => {
  42. const updateOperationValue = reducer["spec_update_operation_value"]
  43. const state = fromJS({
  44. resolved: {
  45. "paths": {
  46. "/pet": {
  47. "post": null
  48. }
  49. }
  50. }
  51. })
  52. let result = updateOperationValue(state, {
  53. payload: {
  54. path: ["/pet", "post"],
  55. value: "application/json",
  56. key: "consumes_value"
  57. }
  58. })
  59. expect(result.toJS()).toEqual(state.toJS())
  60. })
  61. })
  62. describe("set response value", function() {
  63. it("should combine the response and error objects", () => {
  64. const setResponse = reducer["spec_set_response"]
  65. const path = "/pet/post"
  66. const method = "POST"
  67. const state = fromJS({})
  68. const result = setResponse(state, {
  69. payload: {
  70. path: path,
  71. method: method,
  72. res: {
  73. error: true,
  74. err: {
  75. message: "Not Found",
  76. name: "Error",
  77. response: {
  78. data: "response data",
  79. headers: {
  80. key: "value"
  81. },
  82. ok: false,
  83. status: 404,
  84. statusText: "Not Found"
  85. },
  86. status: 404,
  87. statusCode: 404
  88. }
  89. }
  90. }
  91. })
  92. let expectedResult = {
  93. error: true,
  94. message: "Not Found",
  95. name: "Error",
  96. data: "response data",
  97. headers: {
  98. key: "value"
  99. },
  100. ok: false,
  101. status: 404,
  102. statusCode: 404,
  103. statusText: "Not Found"
  104. }
  105. const response = result.getIn(["responses", path, method]).toJS()
  106. expect(response).toEqual(expectedResult)
  107. })
  108. })
  109. })