fix: update logic for unenrollment (#36)

This commit is contained in:
leangseu-edx
2022-10-07 11:08:00 -04:00
committed by GitHub
parent b327e49f14
commit ab2bf89e25
10 changed files with 66 additions and 75 deletions

View File

@@ -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,

View File

@@ -90,8 +90,7 @@ describe('lms api methods', () => {
).toEqual(
utils.post(utils.stringifyUrl(
urls.courseUnenroll,
{ [apiKeys.courseId]: testCourseId, ...unenrollmentAction },
)),
), { [apiKeys.courseId]: testCourseId, ...unenrollmentAction }),
);
});
});

View File

@@ -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;

View File

@@ -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', () => {