Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: URLs get the current value of LMS_BASE_URL from getConfig() #284

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const CollapseMenuBody = ({ isOpen }) => {
<Button as="a" href="/" variant="inverse-primary">
{formatMessage(messages.course)}
</Button>
<Button as="a" href={urls.programsUrl} variant="inverse-primary">
<Button as="a" href={urls.programsUrl()} variant="inverse-primary">
{formatMessage(messages.program)}
</Button>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ExpandedHeader = () => {
</Button>
<Button
as="a"
href={urls.programsUrl}
href={urls.programsUrl()}
variant="inverse-primary"
className="p-4"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ExpandedHeader from '.';
import { useIsCollapsed } from '../hooks';

jest.mock('data/services/lms/urls', () => ({
programsUrl: 'programsUrl',
programsUrl: () => 'programsUrl',
baseAppUrl: url => (`http://localhost:18000${url}`),
}));

Expand Down
6 changes: 3 additions & 3 deletions src/data/services/lms/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ export const deleteEntitlementEnrollment = ({ uuid, isRefundable }) => client()
);

export const updateEmailSettings = ({ courseId, enable }) => post(
urls.updateEmailSettings,
urls.updateEmailSettings(),
{ [apiKeys.courseId]: courseId, ...(enable && enableEmailsAction) },
);

export const unenrollFromCourse = ({ courseId }) => post(
urls.courseUnenroll,
urls.courseUnenroll(),
{ [apiKeys.courseId]: courseId, ...unenrollmentAction },
);

export const logEvent = ({ eventName, data, courseId }) => post(urls.event, {
export const logEvent = ({ eventName, data, courseId }) => post(urls.event(), {
courserun_key: courseId,
event_type: eventName,
page: window.location.href,
Expand Down
8 changes: 4 additions & 4 deletions src/data/services/lms/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('lms api methods', () => {
expect(
api.updateEmailSettings({ courseId, enable: false }),
).toEqual(
utils.post(urls.updateEmailSettings, { [apiKeys.courseId]: courseId }),
utils.post(urls.updateEmailSettings(), { [apiKeys.courseId]: courseId }),
);
});
});
Expand All @@ -87,7 +87,7 @@ describe('lms api methods', () => {
api.updateEmailSettings({ courseId, enable: true }),
).toEqual(
utils.post(
urls.updateEmailSettings,
urls.updateEmailSettings(),
{ [apiKeys.courseId]: courseId, ...enableEmailsAction },
),
);
Expand All @@ -100,7 +100,7 @@ describe('lms api methods', () => {
api.unenrollFromCourse({ courseId }),
).toEqual(
utils.post(
urls.courseUnenroll,
urls.courseUnenroll(),
{ [apiKeys.courseId]: courseId, ...unenrollmentAction },
),
);
Expand All @@ -116,7 +116,7 @@ describe('lms api methods', () => {
expect(
api.logEvent({ courseId, eventName, data }),
).toEqual(
utils.post(urls.event, {
utils.post(urls.event(), {
courserun_key: courseId,
event_type: eventName,
page: href,
Expand Down
8 changes: 4 additions & 4 deletions src/data/services/lms/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export const getApiUrl = () => (`${getConfig().LMS_BASE_URL}/api`);

const getInitApiUrl = () => (`${getApiUrl()}/learner_home/init`);

const event = `${getBaseUrl()}/event`;
const courseUnenroll = `${getBaseUrl()}/change_enrollment`;
const updateEmailSettings = `${getApiUrl()}/change_email_settings`;
const event = () => `${getBaseUrl()}/event`;
const courseUnenroll = () => `${getBaseUrl()}/change_enrollment`;
const updateEmailSettings = () => `${getApiUrl()}/change_email_settings`;
const entitlementEnrollment = (uuid) => `${getApiUrl()}/entitlements/v1/entitlements/${uuid}/enrollments`;

// if url is null or absolute, return it as is
Expand All @@ -22,7 +22,7 @@ export const baseAppUrl = (url) => updateUrl(getBaseUrl(), url);
export const learningMfeUrl = (url) => updateUrl(getConfig().LEARNING_BASE_URL, url);

// static view url
const programsUrl = baseAppUrl('/dashboard/programs');
const programsUrl = () => baseAppUrl('/dashboard/programs');

export const creditPurchaseUrl = (courseId) => `${getEcommerceUrl()}/credit/checkout/${courseId}/`;
export const creditRequestUrl = (providerId) => `${getApiUrl()}/credit/v1/providers/${providerId}/request/`;
Expand Down
Loading