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 <braden@opencraft.com>
This commit is contained in:
22
package-lock.json
generated
22
package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -2380,13 +2380,10 @@ describe('<CourseOutline />', () => {
|
||||
|
||||
// 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('<CourseOutline />', () => {
|
||||
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',
|
||||
|
||||
@@ -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 = [];
|
||||
|
||||
@@ -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];
|
||||
});
|
||||
@@ -111,7 +111,6 @@ describe('group configurations API calls', () => {
|
||||
axiosMock
|
||||
.onDelete(
|
||||
getLegacyApiUrl(courseId, parentGroupId, groupId),
|
||||
updatedContentGroups,
|
||||
)
|
||||
.reply(200, response);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user