Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

135 строки
3.1 KiB

  1. /* eslint-env mocha */
  2. import expect, { createSpy } from "expect"
  3. import { fromJS } from "immutable"
  4. import { execute, executeRequest } from "corePlugins/spec/actions"
  5. describe("spec plugin - actions", function(){
  6. describe("execute", function(){
  7. xit("should collect a full request and call fn.executeRequest", function(){
  8. // Given
  9. const system = {
  10. fn: {
  11. fetch: 1
  12. },
  13. specActions: {
  14. executeRequest: createSpy()
  15. },
  16. specSelectors: {
  17. spec: () => fromJS({spec: 1}),
  18. parameterValues: () => fromJS({values: 2}),
  19. contentTypeValues: () => fromJS({requestContentType: "one", responseContentType: "two"})
  20. }
  21. }
  22. // When
  23. let executeFn = execute({ path: "/one", method: "get"})
  24. executeFn(system)
  25. // Then
  26. expect(system.specActions.executeRequest.calls[0].arguments[0]).toEqual({
  27. fetch: 1,
  28. method: "get",
  29. pathName: "/one",
  30. parameters: {
  31. values: 2
  32. },
  33. requestContentType: "one",
  34. responseContentType: "two",
  35. spec: {
  36. spec: 1
  37. }
  38. })
  39. })
  40. xit("should allow passing _extra_ properties to executeRequest", function(){
  41. // Given
  42. const system = {
  43. fn: {},
  44. specActions: {
  45. executeRequest: createSpy()
  46. },
  47. specSelectors: {
  48. spec: () => fromJS({}),
  49. parameterValues: () => fromJS({}),
  50. contentTypeValues: () => fromJS({})
  51. }
  52. }
  53. // When
  54. let executeFn = execute({ hi: "hello" })
  55. executeFn(system)
  56. // Then
  57. expect(system.specActions.executeRequest.calls[0].arguments[0]).toInclude({hi: "hello"})
  58. })
  59. })
  60. describe("executeRequest", function(){
  61. xit("should call fn.execute with arg ", function(){
  62. const system = {
  63. fn: {
  64. execute: createSpy().andReturn(Promise.resolve())
  65. },
  66. specActions: {
  67. setResponse: createSpy()
  68. }
  69. }
  70. // When
  71. let executeFn = executeRequest({one: 1})
  72. let res = executeFn(system)
  73. // Then
  74. expect(res).toBeA(Promise)
  75. expect(system.fn.execute.calls.length).toEqual(1)
  76. expect(system.fn.execute.calls[0].arguments[0]).toEqual({
  77. one: 1
  78. })
  79. })
  80. })
  81. xit("should call specActions.setResponse, when fn.execute resolves", function(){
  82. const response = {serverResponse: true}
  83. const system = {
  84. fn: {
  85. execute: createSpy().andReturn(Promise.resolve(response))
  86. },
  87. specActions: {
  88. setResponse: createSpy()
  89. },
  90. errActions: {
  91. newSpecErr: createSpy()
  92. }
  93. }
  94. // When
  95. let executeFn = executeRequest({
  96. pathName: "/one",
  97. method: "GET"
  98. })
  99. let executePromise = executeFn(system)
  100. // Then
  101. return executePromise.then( () => {
  102. expect(system.specActions.setResponse.calls.length).toEqual(1)
  103. expect(system.specActions.setResponse.calls[0].arguments).toEqual([
  104. "/one",
  105. "GET",
  106. response
  107. ])
  108. })
  109. })
  110. it.skip("should call errActions.newErr, if the fn.execute rejects", function(){
  111. })
  112. })