From 2ba536d55905efe4acd6a46718dec426dca89e9c Mon Sep 17 00:00:00 2001 From: Eric Cheng <68196762+import-brain@users.noreply.github.com> Date: Mon, 4 Oct 2021 09:45:44 -0400 Subject: [PATCH] refactor: enforce consistent camelCase in const names, add comments, condense multiple single-line comments into one multi-line comment (#43699) --- api-server/src/server/utils/donation.js | 15 ++++++++++++--- curriculum/test/test-challenges.js | 10 ++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/api-server/src/server/utils/donation.js b/api-server/src/server/utils/donation.js index 0a8b69fe68..269cf6c412 100644 --- a/api-server/src/server/utils/donation.js +++ b/api-server/src/server/utils/donation.js @@ -6,7 +6,7 @@ import keys from '../../../../config/secrets'; const log = debug('fcc:boot:donate'); -const paypalverifyWebhookURL = +const paypalVerifyWebhookURL = keys.paypal.verifyWebhookURL || `https://api.sandbox.paypal.com/v1/notifications/verify-webhook-signature`; const paypalTokenURL = @@ -49,7 +49,7 @@ export async function verifyWebHook(headers, body, token, webhookId) { webhook_event: webhookEventBody }; - const response = await axios.post(paypalverifyWebhookURL, payload, { + const response = await axios.post(paypalVerifyWebhookURL, payload, { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` @@ -60,6 +60,7 @@ export async function verifyWebHook(headers, body, token, webhookId) { return body; } else { throw { + // if verification fails, throw token verification error message: `Failed token verification.`, type: 'FailedPaypalTokenVerificationError' }; @@ -86,6 +87,7 @@ export function verifyWebHookType(req) { export const createAsyncUserDonation = (user, donation) => { log(`Creating donation:${donation.subscriptionId}`); + // log user donation user .createDonation(donation) .toPromise() @@ -95,6 +97,7 @@ export const createAsyncUserDonation = (user, donation) => { }; export function createDonationObj(body) { + // creates donation object const { resource: { id, @@ -163,6 +166,7 @@ export async function cancelDonation(body, app) { export async function updateUser(body, app) { const { event_type } = body; if (event_type === 'BILLING.SUBSCRIPTION.ACTIVATED') { + // update user status based on new billing subscription events createDonation(body, app); } else if (event_type === 'BILLING.SUBSCRIPTION.CANCELLED') { cancelDonation(body, app); @@ -191,6 +195,10 @@ export async function createStripeCardDonation(req, res, stripe) { }; } + /* + * if user is already donating and the donation isn't one time only, + * throw error + */ if (user.isDonating && duration !== 'onetime') { throw { message: `User already has active recurring donation(s).`, @@ -213,10 +221,11 @@ export async function createStripeCardDonation(req, res, stripe) { }; } log(`Stripe customer with id ${customerId} created`); - + // log creation of Stripe customer event let subscriptionId; try { const subscription = await stripe.subscriptions.create({ + // create Stripe subscription customer: customerId, items: [ { diff --git a/curriculum/test/test-challenges.js b/curriculum/test/test-challenges.js index fe3363d466..283f187529 100644 --- a/curriculum/test/test-challenges.js +++ b/curriculum/test/test-challenges.js @@ -347,10 +347,12 @@ function populateTestsForLang({ lang, challenges, meta }) { ); } - // Then we compare the number of times each comment appears in the - // translated text (commentMap) with the number of replacements - // made during translation (challenge.__commentCounts). If they - // differ, the translation must have gone wrong + /* + * Then we compare the number of times each comment appears in the + * translated text (commentMap) with the number of replacements + * made during translation (challenge.__commentCounts). If they + * differ, the translation must have gone wrong + */ const commentMap = new Map(Object.entries(comments));