Skip to content

Commit

Permalink
fix: adds optional params for when process.env isn't configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jlajoie committed Aug 11, 2020
1 parent 85e9316 commit 832fcf1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/learnerPortalLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ function cacheLinks(userId, links) {
);
}

async function fetchLearnerPortalLinks(apiClient, userId) {
async function fetchLearnerPortalLinks(
apiClient,
userId,
learnerPortalHostname = process.env.ENTERPRISE_LEARNER_PORTAL_HOSTNAME,
lmsBaseUrl = process.env.LMS_BASE_URL,
) {
const learnerPortalLinks = [];
const learnerPortalHostname = process.env.ENTERPRISE_LEARNER_PORTAL_HOSTNAME;
if (!learnerPortalHostname) {
return learnerPortalLinks;
}
const response = await fetchEnterpriseCustomers(apiClient);
const response = await fetchEnterpriseCustomers(apiClient, lmsBaseUrl);
const enterpriseCustomers = response.data.results;
try {
for (let i = 0; i < enterpriseCustomers.length; i += 1) {
Expand Down Expand Up @@ -72,7 +76,12 @@ function getCachedLearnerPortalLinks(userId) {
return null;
}

export default async function getLearnerPortalLinks(apiClient, authenticatedUser) {
export default async function getLearnerPortalLinks(
apiClient,
authenticatedUser,
learnerPortalHostname = process.env.ENTERPRISE_LEARNER_PORTAL_HOSTNAME,
lmsBaseUrl = process.env.LMS_BASE_URL,
) {
let learnerPortalLinks = [];

if (authenticatedUser !== null && isEnterpriseUser(authenticatedUser)) {
Expand All @@ -82,7 +91,12 @@ export default async function getLearnerPortalLinks(apiClient, authenticatedUser
if (cachedLinks != null) {
learnerPortalLinks = learnerPortalLinks.concat(cachedLinks);
} else {
const links = await fetchLearnerPortalLinks(apiClient, userId);
const links = await fetchLearnerPortalLinks(
apiClient,
userId,
learnerPortalHostname,
lmsBaseUrl,
);
learnerPortalLinks = learnerPortalLinks.concat(links);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fetchEnterpriseCustomers = apiClient => apiClient.get(`${process.env.LMS_BASE_URL}/enterprise/api/v1/enterprise-customer/`);
const fetchEnterpriseCustomers = (apiClient, lmsBaseUrl = process.env.LMS_BASE_URL) => apiClient.get(`${lmsBaseUrl}/enterprise/api/v1/enterprise-customer/`);

// eslint-disable-next-line import/prefer-default-export
export { fetchEnterpriseCustomers };

0 comments on commit 832fcf1

Please sign in to comment.