From 8e3ea89339e4ab6258c01f8e92436ee5dc055889 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 23:27:28 +0000 Subject: [PATCH] chore(deps): update dependency axios-mock-adapter to v2 (#2304) * chore(deps): update dependency axios-mock-adapter to v2 * test: update tests for compatibility with axios-mock-adapter v2 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Braden MacDonald --- package-lock.json | 22 +++++++++++++++---- package.json | 2 +- src/course-outline/CourseOutline.test.tsx | 18 +++++---------- src/files-and-videos/videos-page/data/api.js | 2 ++ .../data/{api.test.js => api.test.ts} | 16 +++++++++----- src/group-configurations/data/api.test.js | 1 - 6 files changed, 37 insertions(+), 24 deletions(-) rename src/files-and-videos/videos-page/data/{api.test.js => api.test.ts} (95%) diff --git a/package-lock.json b/package-lock.json index 2c687a07b..37532c0c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -88,7 +88,7 @@ "@types/lodash": "^4.17.17", "@types/react": "^18", "@types/react-dom": "^18", - "axios-mock-adapter": "1.22.0", + "axios-mock-adapter": "2.1.0", "eslint-import-resolver-webpack": "^0.13.8", "fetch-mock-jest": "^1.5.1", "jest-canvas-mock": "^2.5.2", @@ -2843,6 +2843,19 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/@edx/frontend-component-header/node_modules/axios-mock-adapter": { + "version": "1.22.0", + "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", + "integrity": "sha512-dmI0KbkyAhntUR05YY96qg2H6gg0XMl2+qTW0xmYg6Up+BFBAJYRLROMXRdDEL06/Wqwa0TJThAYvFtSFdRCZw==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "is-buffer": "^2.0.5" + }, + "peerDependencies": { + "axios": ">= 0.17.0" + } + }, "node_modules/@edx/frontend-component-header/node_modules/ci-info": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.3.0.tgz", @@ -8356,9 +8369,10 @@ } }, "node_modules/axios-mock-adapter": { - "version": "1.22.0", - "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", - "integrity": "sha512-dmI0KbkyAhntUR05YY96qg2H6gg0XMl2+qTW0xmYg6Up+BFBAJYRLROMXRdDEL06/Wqwa0TJThAYvFtSFdRCZw==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-2.1.0.tgz", + "integrity": "sha512-AZUe4OjECGCNNssH8SOdtneiQELsqTsat3SQQCWLPjN436/H+L9AjWfV7bF+Zg/YL9cgbhrz5671hoh+Tbn98w==", + "dev": true, "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.3", diff --git a/package.json b/package.json index 0020e91ce..db3a39dde 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "@types/lodash": "^4.17.17", "@types/react": "^18", "@types/react-dom": "^18", - "axios-mock-adapter": "1.22.0", + "axios-mock-adapter": "2.1.0", "eslint-import-resolver-webpack": "^0.13.8", "fetch-mock-jest": "^1.5.1", "jest-canvas-mock": "^2.5.2", diff --git a/src/course-outline/CourseOutline.test.tsx b/src/course-outline/CourseOutline.test.tsx index 4fcc13963..5d3b540f9 100644 --- a/src/course-outline/CourseOutline.test.tsx +++ b/src/course-outline/CourseOutline.test.tsx @@ -2380,13 +2380,10 @@ describe('', () => { // Delay to ensure we see "Please wait." // Without the delay the success message renders too quickly - const delayedResponse = axiosMock + axiosMock .onGet(exportTags(courseId)) - // Issue with types in upstream lib, should be fixed by this PR - // https://github.com/ctimmerm/axios-mock-adapter/pull/391/files - // @ts-ignore-next-line - .withDelayInMs(500); - delayedResponse(200, expectedResponse); + .withDelayInMs(500) + .reply(200, expectedResponse); jest.mocked(useLocation).mockReturnValue({ pathname: '/foo-bar', @@ -2410,13 +2407,10 @@ describe('', () => { it('should show toast on export tags error', async () => { // Delay to ensure we see "Please wait." // Without the delay the error renders too quickly - const delayedResponse = axiosMock + axiosMock .onGet(exportTags(courseId)) - // Issue with types in upstream lib, should be fixed by this PR - // https://github.com/ctimmerm/axios-mock-adapter/pull/391/files - // @ts-ignore-next-line - .withDelayInMs(500); - delayedResponse(404); + .withDelayInMs(500) + .reply(404); jest.mocked(useLocation).mockReturnValue({ pathname: '/foo-bar', diff --git a/src/files-and-videos/videos-page/data/api.js b/src/files-and-videos/videos-page/data/api.js index 1a5462dda..bf515ed64 100644 --- a/src/files-and-videos/videos-page/data/api.js +++ b/src/files-and-videos/videos-page/data/api.js @@ -32,6 +32,8 @@ export async function getVideos(courseId) { } export async function getAllUsagePaths({ courseId, videoIds }) { + // Hack: pass 'videoId' into the 'config' object; it will be ignored by axios + // but allows us to read it out later to easily get the videoId per result. const apiPromises = videoIds.map(id => getAuthenticatedHttpClient() .get(`${getVideosUrl(courseId)}/${id}/usage`, { videoId: id })); const updatedUsageLocations = []; diff --git a/src/files-and-videos/videos-page/data/api.test.js b/src/files-and-videos/videos-page/data/api.test.ts similarity index 95% rename from src/files-and-videos/videos-page/data/api.test.js rename to src/files-and-videos/videos-page/data/api.test.ts index 02cf14d2b..310fe8637 100644 --- a/src/files-and-videos/videos-page/data/api.test.js +++ b/src/files-and-videos/videos-page/data/api.test.ts @@ -9,8 +9,8 @@ import { jest.mock('file-saver'); -let axiosMock; -let axiosUnauthenticatedMock; +let axiosMock: MockAdapter; +let axiosUnauthenticatedMock: MockAdapter; describe('api.js', () => { beforeEach(() => { @@ -85,14 +85,15 @@ describe('api.js', () => { expect(actual).toEqual(expected); }); it('pushes an empty usageLocations field when video api call fails', async () => { - axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] }).reply(404); + axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`) + .reply(404); const expected = []; const actual = await getAllUsagePaths({ courseId, videoIds }); expect(actual).toEqual(expected); }); it('sets activeStatus to active', async () => { const usageLocations = [{ link: '/test', name: 'test' }]; - axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] }) + axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`) .reply(200, { usageLocations }); const expected = [{ id: videoIds[0], usageLocations, activeStatus: 'active' }]; const actual = await getAllUsagePaths({ courseId, videoIds }); @@ -100,7 +101,7 @@ describe('api.js', () => { }); it('sets activeStatus to inactive', async () => { const usageLocations = []; - axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] }) + axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`) .reply(200, { usageLocations }); const expected = [{ id: videoIds[0], usageLocations, activeStatus: 'inactive' }]; const actual = await getAllUsagePaths({ courseId, videoIds }); @@ -129,8 +130,11 @@ describe('api.js', () => { axiosUnauthenticatedMock.onPut(mockUrl).reply((config) => { const total = 1024; // mocked file size const progress = 0.4; + const loaded = total * progress; if (config.onUploadProgress) { - config.onUploadProgress({ loaded: total * progress, total }); + config.onUploadProgress({ + loaded, total, bytes: loaded, lengthComputable: true, + }); } return [200, expectedResult]; }); diff --git a/src/group-configurations/data/api.test.js b/src/group-configurations/data/api.test.js index fe5ef9fae..6109ca3be 100644 --- a/src/group-configurations/data/api.test.js +++ b/src/group-configurations/data/api.test.js @@ -111,7 +111,6 @@ describe('group configurations API calls', () => { axiosMock .onDelete( getLegacyApiUrl(courseId, parentGroupId, groupId), - updatedContentGroups, ) .reply(200, response);