Files
frontend-app-discussions/src/discussions/posts/data/api.test.js
Adolfo R. Brandes 0c71e8b5b7 feat: Support runtime configuration (second attempt)
(This reintroduces the change in 9f84230c that was later reverted by
67b0b33a.)

frontend-platform supports runtime configuration since 2.5.0 (see the PR
that introduced it[1], but it requires MFE cooperation.  This implements
just that: by avoiding making configuration values constant, it should
now be possible to change them after initialization.

Almost all changes here relate to the `LMS_BASE_URL` setting, which in
most places was treated as a constant.

[1] https://github.com/openedx/frontend-platform/pull/335
2022-12-20 17:54:21 +05:00

37 lines
1.0 KiB
JavaScript

import MockAdapter from 'axios-mock-adapter';
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { initializeMockApp } from '@edx/frontend-platform/testing';
import { getCoursesApiUrl, uploadFile } from './api';
const courseId = 'course-v1:edX+TestX+Test_Course';
const coursesApiUrl = getCoursesApiUrl();
let axiosMock = null;
describe('Threads/Posts api tests', () => {
beforeEach(() => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
});
afterEach(() => {
axiosMock.reset();
});
test('successfully completes upload requests', async () => {
axiosMock.onPost(`${coursesApiUrl}${courseId}/upload`)
.reply(200, { location: 'http://test/file.jpg' });
const response = await uploadFile(new Blob(['sample data']), 'sample_file.jpg', courseId, 'root');
expect(response.location).toEqual('http://test/file.jpg');
});
});