fix: update logic for unenrollment (#36)
This commit is contained in:
@@ -34,10 +34,10 @@ const updateEmailSettings = ({ courseId, enable }) => post(stringifyUrl(
|
||||
{ [apiKeys.courseId]: courseId, ...(enable && enableEmailsAction) },
|
||||
));
|
||||
|
||||
const unenrollFromCourse = ({ courseId }) => post(stringifyUrl(
|
||||
urls.courseUnenroll,
|
||||
{ [apiKeys.courseId]: courseId, ...unenrollmentAction },
|
||||
));
|
||||
const unenrollFromCourse = ({ courseId }) => post(stringifyUrl(urls.courseUnenroll), {
|
||||
[apiKeys.courseId]: courseId,
|
||||
...unenrollmentAction,
|
||||
});
|
||||
|
||||
export default {
|
||||
initializeList,
|
||||
|
||||
@@ -90,8 +90,7 @@ describe('lms api methods', () => {
|
||||
).toEqual(
|
||||
utils.post(utils.stringifyUrl(
|
||||
urls.courseUnenroll,
|
||||
{ [apiKeys.courseId]: testCourseId, ...unenrollmentAction },
|
||||
)),
|
||||
), { [apiKeys.courseId]: testCourseId, ...unenrollmentAction }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,10 +10,11 @@ export const get = (...args) => getAuthenticatedHttpClient().get(...args);
|
||||
/**
|
||||
* post(url, data)
|
||||
* simple wrapper providing an authenticated Http client post action
|
||||
* queryString.stringify is used to convert the object to query string with = and &
|
||||
* @param {string} url - target url
|
||||
* @param {object|string} data - post payload
|
||||
* @param {object|string} body - post payload
|
||||
*/
|
||||
export const post = (...args) => getAuthenticatedHttpClient().post(...args);
|
||||
export const post = (url, body) => getAuthenticatedHttpClient().post(url, queryString.stringify(body));
|
||||
|
||||
export const client = getAuthenticatedHttpClient;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as utils from './utils';
|
||||
|
||||
jest.mock('query-string', () => ({
|
||||
stringifyUrl: jest.fn((url, options) => ({ url, options })),
|
||||
stringify: jest.fn((data) => data),
|
||||
}));
|
||||
jest.mock('@edx/frontend-platform/auth', () => ({
|
||||
getAuthenticatedHttpClient: jest.fn(),
|
||||
@@ -22,8 +23,15 @@ describe('lms service utils', () => {
|
||||
it('forwards arguments to authenticatedHttpClient().post', () => {
|
||||
const post = jest.fn((...args) => ({ post: args }));
|
||||
getAuthenticatedHttpClient.mockReturnValue({ post });
|
||||
const args = ['some', 'args', 'for', 'the', 'test'];
|
||||
expect(utils.post(...args)).toEqual(post(...args));
|
||||
const url = 'some url';
|
||||
const body = {
|
||||
some: 'body',
|
||||
for: 'the',
|
||||
test: 'yay',
|
||||
};
|
||||
const expectedUrl = utils.post(url, body);
|
||||
expect(queryString.stringify).toHaveBeenCalledWith(body);
|
||||
expect(expectedUrl).toEqual(post(url, body));
|
||||
});
|
||||
});
|
||||
describe('stringifyUrl', () => {
|
||||
|
||||
Reference in New Issue
Block a user