Skip to content

Commit 8e3ea89

Browse files
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 <[email protected]>
1 parent 537b329 commit 8e3ea89

File tree

6 files changed

+37
-24
lines changed

6 files changed

+37
-24
lines changed

package-lock.json

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"@types/lodash": "^4.17.17",
112112
"@types/react": "^18",
113113
"@types/react-dom": "^18",
114-
"axios-mock-adapter": "1.22.0",
114+
"axios-mock-adapter": "2.1.0",
115115
"eslint-import-resolver-webpack": "^0.13.8",
116116
"fetch-mock-jest": "^1.5.1",
117117
"jest-canvas-mock": "^2.5.2",

src/course-outline/CourseOutline.test.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,13 +2380,10 @@ describe('<CourseOutline />', () => {
23802380

23812381
// Delay to ensure we see "Please wait."
23822382
// Without the delay the success message renders too quickly
2383-
const delayedResponse = axiosMock
2383+
axiosMock
23842384
.onGet(exportTags(courseId))
2385-
// Issue with types in upstream lib, should be fixed by this PR
2386-
// https://github.com/ctimmerm/axios-mock-adapter/pull/391/files
2387-
// @ts-ignore-next-line
2388-
.withDelayInMs(500);
2389-
delayedResponse(200, expectedResponse);
2385+
.withDelayInMs(500)
2386+
.reply(200, expectedResponse);
23902387

23912388
jest.mocked(useLocation).mockReturnValue({
23922389
pathname: '/foo-bar',
@@ -2410,13 +2407,10 @@ describe('<CourseOutline />', () => {
24102407
it('should show toast on export tags error', async () => {
24112408
// Delay to ensure we see "Please wait."
24122409
// Without the delay the error renders too quickly
2413-
const delayedResponse = axiosMock
2410+
axiosMock
24142411
.onGet(exportTags(courseId))
2415-
// Issue with types in upstream lib, should be fixed by this PR
2416-
// https://github.com/ctimmerm/axios-mock-adapter/pull/391/files
2417-
// @ts-ignore-next-line
2418-
.withDelayInMs(500);
2419-
delayedResponse(404);
2412+
.withDelayInMs(500)
2413+
.reply(404);
24202414

24212415
jest.mocked(useLocation).mockReturnValue({
24222416
pathname: '/foo-bar',

src/files-and-videos/videos-page/data/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export async function getVideos(courseId) {
3232
}
3333

3434
export async function getAllUsagePaths({ courseId, videoIds }) {
35+
// Hack: pass 'videoId' into the 'config' object; it will be ignored by axios
36+
// but allows us to read it out later to easily get the videoId per result.
3537
const apiPromises = videoIds.map(id => getAuthenticatedHttpClient()
3638
.get(`${getVideosUrl(courseId)}/${id}/usage`, { videoId: id }));
3739
const updatedUsageLocations = [];

src/files-and-videos/videos-page/data/api.test.js renamed to src/files-and-videos/videos-page/data/api.test.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99

1010
jest.mock('file-saver');
1111

12-
let axiosMock;
13-
let axiosUnauthenticatedMock;
12+
let axiosMock: MockAdapter;
13+
let axiosUnauthenticatedMock: MockAdapter;
1414

1515
describe('api.js', () => {
1616
beforeEach(() => {
@@ -85,22 +85,23 @@ describe('api.js', () => {
8585
expect(actual).toEqual(expected);
8686
});
8787
it('pushes an empty usageLocations field when video api call fails', async () => {
88-
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] }).reply(404);
88+
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`)
89+
.reply(404);
8990
const expected = [];
9091
const actual = await getAllUsagePaths({ courseId, videoIds });
9192
expect(actual).toEqual(expected);
9293
});
9394
it('sets activeStatus to active', async () => {
9495
const usageLocations = [{ link: '/test', name: 'test' }];
95-
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] })
96+
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`)
9697
.reply(200, { usageLocations });
9798
const expected = [{ id: videoIds[0], usageLocations, activeStatus: 'active' }];
9899
const actual = await getAllUsagePaths({ courseId, videoIds });
99100
expect(actual).toEqual(expected);
100101
});
101102
it('sets activeStatus to inactive', async () => {
102103
const usageLocations = [];
103-
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`, { videoId: videoIds[0] })
104+
axiosMock.onGet(`${getVideosUrl(courseId)}/${videoIds[0]}/usage`)
104105
.reply(200, { usageLocations });
105106
const expected = [{ id: videoIds[0], usageLocations, activeStatus: 'inactive' }];
106107
const actual = await getAllUsagePaths({ courseId, videoIds });
@@ -129,8 +130,11 @@ describe('api.js', () => {
129130
axiosUnauthenticatedMock.onPut(mockUrl).reply((config) => {
130131
const total = 1024; // mocked file size
131132
const progress = 0.4;
133+
const loaded = total * progress;
132134
if (config.onUploadProgress) {
133-
config.onUploadProgress({ loaded: total * progress, total });
135+
config.onUploadProgress({
136+
loaded, total, bytes: loaded, lengthComputable: true,
137+
});
134138
}
135139
return [200, expectedResult];
136140
});

src/group-configurations/data/api.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ describe('group configurations API calls', () => {
111111
axiosMock
112112
.onDelete(
113113
getLegacyApiUrl(courseId, parentGroupId, groupId),
114-
updatedContentGroups,
115114
)
116115
.reply(200, response);
117116

0 commit comments

Comments
 (0)