refactor: enforce consistent camelCase in const names, add comments, condense multiple single-line comments into one multi-line comment (#43699)

This commit is contained in:
Eric Cheng
2021-10-04 09:45:44 -04:00
committed by GitHub
parent 38740f256c
commit 2ba536d559
2 changed files with 18 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import keys from '../../../../config/secrets';
const log = debug('fcc:boot:donate'); const log = debug('fcc:boot:donate');
const paypalverifyWebhookURL = const paypalVerifyWebhookURL =
keys.paypal.verifyWebhookURL || keys.paypal.verifyWebhookURL ||
`https://api.sandbox.paypal.com/v1/notifications/verify-webhook-signature`; `https://api.sandbox.paypal.com/v1/notifications/verify-webhook-signature`;
const paypalTokenURL = const paypalTokenURL =
@ -49,7 +49,7 @@ export async function verifyWebHook(headers, body, token, webhookId) {
webhook_event: webhookEventBody webhook_event: webhookEventBody
}; };
const response = await axios.post(paypalverifyWebhookURL, payload, { const response = await axios.post(paypalVerifyWebhookURL, payload, {
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Bearer ${token}` Authorization: `Bearer ${token}`
@ -60,6 +60,7 @@ export async function verifyWebHook(headers, body, token, webhookId) {
return body; return body;
} else { } else {
throw { throw {
// if verification fails, throw token verification error
message: `Failed token verification.`, message: `Failed token verification.`,
type: 'FailedPaypalTokenVerificationError' type: 'FailedPaypalTokenVerificationError'
}; };
@ -86,6 +87,7 @@ export function verifyWebHookType(req) {
export const createAsyncUserDonation = (user, donation) => { export const createAsyncUserDonation = (user, donation) => {
log(`Creating donation:${donation.subscriptionId}`); log(`Creating donation:${donation.subscriptionId}`);
// log user donation
user user
.createDonation(donation) .createDonation(donation)
.toPromise() .toPromise()
@ -95,6 +97,7 @@ export const createAsyncUserDonation = (user, donation) => {
}; };
export function createDonationObj(body) { export function createDonationObj(body) {
// creates donation object
const { const {
resource: { resource: {
id, id,
@ -163,6 +166,7 @@ export async function cancelDonation(body, app) {
export async function updateUser(body, app) { export async function updateUser(body, app) {
const { event_type } = body; const { event_type } = body;
if (event_type === 'BILLING.SUBSCRIPTION.ACTIVATED') { if (event_type === 'BILLING.SUBSCRIPTION.ACTIVATED') {
// update user status based on new billing subscription events
createDonation(body, app); createDonation(body, app);
} else if (event_type === 'BILLING.SUBSCRIPTION.CANCELLED') { } else if (event_type === 'BILLING.SUBSCRIPTION.CANCELLED') {
cancelDonation(body, app); 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') { if (user.isDonating && duration !== 'onetime') {
throw { throw {
message: `User already has active recurring donation(s).`, 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(`Stripe customer with id ${customerId} created`);
// log creation of Stripe customer event
let subscriptionId; let subscriptionId;
try { try {
const subscription = await stripe.subscriptions.create({ const subscription = await stripe.subscriptions.create({
// create Stripe subscription
customer: customerId, customer: customerId,
items: [ items: [
{ {

View File

@ -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 * Then we compare the number of times each comment appears in the
// made during translation (challenge.__commentCounts). If they * translated text (commentMap) with the number of replacements
// differ, the translation must have gone wrong * made during translation (challenge.__commentCounts). If they
* differ, the translation must have gone wrong
*/
const commentMap = new Map(Object.entries(comments)); const commentMap = new Map(Object.entries(comments));