From cc336f904eb55a1b746d35bb94834b00a773c1a2 Mon Sep 17 00:00:00 2001 From: Aislinn Hayes Date: Tue, 8 Sep 2020 11:47:24 +0100 Subject: [PATCH 1/2] Comment out all the axios-cache-adaptor functionality and run `yarn workspace @test/parentApp test --detect-leaks` --- packages/libs/core-api/src/axiosHelpers.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/libs/core-api/src/axiosHelpers.js b/packages/libs/core-api/src/axiosHelpers.js index 7b85220..7483bfd 100644 --- a/packages/libs/core-api/src/axiosHelpers.js +++ b/packages/libs/core-api/src/axiosHelpers.js @@ -1,6 +1,6 @@ import axios from 'axios'; import axiosRetry from 'axios-retry'; -import { setupCache } from 'axios-cache-adapter'; +// import { setupCache } from 'axios-cache-adapter'; import backoff from './utils/backoff'; // Exported only for unit test coverage @@ -10,12 +10,12 @@ export const customCacheInvalidate = async (config, request) => { } }; -const cache = setupCache({ - // 15 minute cache - maxAge: 15 * 60 * 1000, - // Invalidate only when a specific option is passed through config - invalidate: customCacheInvalidate, -}); +// const cache = setupCache({ +// // 15 minute cache +// maxAge: 15 * 60 * 1000, +// // Invalidate only when a specific option is passed through config +// invalidate: customCacheInvalidate, +// }); export const getHeaderWithoutAuth = (optionalHeaders = {}) => { return { @@ -46,7 +46,7 @@ export const createAxiosCancelable = ({ const canceler = axios.CancelToken.source(); const auth = getHeaderWithoutAuth(); if (withCache) { - auth.adapter = cache.adapter; + // auth.adapter = cache.adapter; } const client = axios.create(auth); axiosRetry(client, backoff(min, max)); From fb104de91053c711b6b5609567e859c4685d2f77 Mon Sep 17 00:00:00 2001 From: Aislinn Hayes Date: Tue, 8 Sep 2020 11:48:03 +0100 Subject: [PATCH 2/2] Update axiosHelpers.test.js --- .../libs/core-api/src/axiosHelpers.test.js | 106 +++++++++--------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/packages/libs/core-api/src/axiosHelpers.test.js b/packages/libs/core-api/src/axiosHelpers.test.js index 15fc3d8..559f554 100644 --- a/packages/libs/core-api/src/axiosHelpers.test.js +++ b/packages/libs/core-api/src/axiosHelpers.test.js @@ -119,58 +119,58 @@ describe('axiosHelpers', () => { expect(backoff).toHaveBeenCalledWith(expectedMin, expectedMax); }); - describe('cache', () => { - beforeEach(() => { - jest.clearAllMocks(); - }); - - it('when withCache is true, axios create is called with adapter', () => { - createAxiosCancelable({ withCache: true }); - - expect(axios.create).toBeCalledWith( - expect.objectContaining({ - adapter: expect.any(Function), - }), - ); - }); - - it('when withCache is false, axios create is called without adapter', () => { - createAxiosCancelable({ withCache: false }); - - expect(axios.create).not.toBeCalledWith( - expect.objectContaining({ - adapter: expect.any(Function), - }), - ); - }); - - it('when withCache not specified, axios create is called without adapter', () => { - createAxiosCancelable(); - - expect(axios.create).not.toBeCalledWith( - expect.objectContaining({ - adapter: expect.any(Function), - }), - ); - }); - - it('when invalidate function on cache is called, it looks for clearCacheEntry in the request before invalidating the cache', async () => { - const mockRemoveItem = jest.fn(); - const mockUuid = 'mockUuid'; - const mockConfig = { - store: { - removeItem: mockRemoveItem, - }, - uuid: mockUuid, - }; - - customCacheInvalidate(mockConfig, {}); - expect(mockRemoveItem).not.toHaveBeenCalled(); - const mockRequest = { clearCacheEntry: true }; - - customCacheInvalidate(mockConfig, mockRequest); - expect(mockRemoveItem).toHaveBeenCalledWith(mockUuid); - }); - }); + // describe('cache', () => { + // beforeEach(() => { + // jest.clearAllMocks(); + // }); + + // it('when withCache is true, axios create is called with adapter', () => { + // createAxiosCancelable({ withCache: true }); + + // expect(axios.create).toBeCalledWith( + // expect.objectContaining({ + // adapter: expect.any(Function), + // }), + // ); + // }); + + // it('when withCache is false, axios create is called without adapter', () => { + // createAxiosCancelable({ withCache: false }); + + // expect(axios.create).not.toBeCalledWith( + // expect.objectContaining({ + // adapter: expect.any(Function), + // }), + // ); + // }); + + // it('when withCache not specified, axios create is called without adapter', () => { + // createAxiosCancelable(); + + // expect(axios.create).not.toBeCalledWith( + // expect.objectContaining({ + // adapter: expect.any(Function), + // }), + // ); + // }); + + // it('when invalidate function on cache is called, it looks for clearCacheEntry in the request before invalidating the cache', async () => { + // const mockRemoveItem = jest.fn(); + // const mockUuid = 'mockUuid'; + // const mockConfig = { + // store: { + // removeItem: mockRemoveItem, + // }, + // uuid: mockUuid, + // }; + + // customCacheInvalidate(mockConfig, {}); + // expect(mockRemoveItem).not.toHaveBeenCalled(); + // const mockRequest = { clearCacheEntry: true }; + + // customCacheInvalidate(mockConfig, mockRequest); + // expect(mockRemoveItem).toHaveBeenCalledWith(mockUuid); + // }); + // }); }); });