Skip to content

Commit

Permalink
fix: URLs get the current value of LMS_BASE_URL from getConfig() open…
Browse files Browse the repository at this point in the history
  • Loading branch information
hinakhadim committed Jan 15, 2024
1 parent bed2c34 commit 34832a2
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
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

0 comments on commit 34832a2

Please sign in to comment.