withCredentials.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { loaded } from "corePlugins/swagger-js/configs-wrap-actions"
  2. describe("swagger-js plugin - withCredentials", () => {
  3. it("should have no effect by default", () => {
  4. const system = {
  5. fn: {
  6. fetch: jest.fn().mockImplementation(() => Promise.resolve())
  7. },
  8. getConfigs: () => ({})
  9. }
  10. const oriExecute = jest.fn()
  11. const loadedFn = loaded(oriExecute, system)
  12. loadedFn()
  13. expect(oriExecute.mock.calls.length).toBe(1)
  14. expect(system.fn.fetch.withCredentials).toBe(undefined)
  15. })
  16. it("should allow setting flag to true via config", () => {
  17. const system = {
  18. fn: {
  19. fetch: jest.fn().mockImplementation(() => Promise.resolve())
  20. },
  21. getConfigs: () => ({
  22. withCredentials: true
  23. })
  24. }
  25. const oriExecute = jest.fn()
  26. const loadedFn = loaded(oriExecute, system)
  27. loadedFn()
  28. expect(oriExecute.mock.calls.length).toBe(1)
  29. expect(system.fn.fetch.withCredentials).toBe(true)
  30. })
  31. it("should allow setting flag to false via config", () => {
  32. const system = {
  33. fn: {
  34. fetch: jest.fn().mockImplementation(() => Promise.resolve())
  35. },
  36. getConfigs: () => ({
  37. withCredentials: false
  38. })
  39. }
  40. const oriExecute = jest.fn()
  41. const loadedFn = loaded(oriExecute, system)
  42. loadedFn()
  43. expect(oriExecute.mock.calls.length).toBe(1)
  44. expect(system.fn.fetch.withCredentials).toBe(false)
  45. })
  46. it("should allow setting flag to true via config as string", () => {
  47. // for query string config
  48. const system = {
  49. fn: {
  50. fetch: jest.fn().mockImplementation(() => Promise.resolve())
  51. },
  52. getConfigs: () => ({
  53. withCredentials: "true"
  54. })
  55. }
  56. const oriExecute = jest.fn()
  57. const loadedFn = loaded(oriExecute, system)
  58. loadedFn()
  59. expect(oriExecute.mock.calls.length).toBe(1)
  60. expect(system.fn.fetch.withCredentials).toBe(true)
  61. })
  62. it("should allow setting flag to false via config as string", () => {
  63. // for query string config
  64. const system = {
  65. fn: {
  66. fetch: jest.fn().mockImplementation(() => Promise.resolve())
  67. },
  68. getConfigs: () => ({
  69. withCredentials: "false"
  70. })
  71. }
  72. const oriExecute = jest.fn()
  73. const loadedFn = loaded(oriExecute, system)
  74. loadedFn()
  75. expect(oriExecute.mock.calls.length).toBe(1)
  76. expect(system.fn.fetch.withCredentials).toBe(false)
  77. })
  78. })