Skip to content

Commit a488bbf

Browse files
authored
Merge pull request #90 from staadecker/upgrade-and-logging
Upgrade packages and enable more logging.
2 parents 8393d1d + 16d6a2b commit a488bbf

File tree

9 files changed

+1651
-2072
lines changed

9 files changed

+1651
-2072
lines changed

components/expired-members-remover/index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ const loadConfigFromGoogleSecretManager = async () => {
6161
/**
6262
* Useful to avoid unhandled promise rejection errors
6363
*/
64-
const errorHandler = (func) => async (...args) => {
65-
try {
66-
await func(...args);
67-
} catch (e) {
68-
console.error(e);
69-
throw e;
70-
}
71-
};
64+
const errorHandler =
65+
(func) =>
66+
async (...args) => {
67+
try {
68+
await func(...args);
69+
} catch (e) {
70+
console.error(e);
71+
throw e;
72+
}
73+
};
7274

7375
const sendRemovingEmail = async (expiredMember) => {
7476
const msg = {
@@ -179,7 +181,7 @@ const getMembersInGroup = async (googleGroupClient) => {
179181
if (!res.data.members) continue; // If no members don't try map()
180182

181183
const emailsForPage = res.data.members.map(
182-
(m) => ({id: m.id, email: parseEmailForComparing(m.email)}) // makes emails lower case and removes . in gmail addresses
184+
(m) => ({ id: m.id, email: parseEmailForComparing(m.email) }) // makes emails lower case and removes . in gmail addresses
183185
);
184186
emails = emails.concat(emailsForPage); // append to list of all emails
185187
} while (pageToken !== undefined);
@@ -227,7 +229,10 @@ const getName = (member) => {
227229
*/
228230
const getExpiredMembers = async (membersInGroup, emailsInDb) => {
229231
const expiredEmails = membersInGroup.filter((member) => {
230-
return !emailsInDb.hasOwnProperty(member.email) || emailsInDb[member.email].expired;
232+
return (
233+
!emailsInDb.hasOwnProperty(member.email) ||
234+
emailsInDb[member.email].expired
235+
);
231236
});
232237

233238
return expiredEmails.map((member) => ({

components/expired-members-remover/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("all tests", () => {
1010
];
1111

1212
for (let test_case of test_data) {
13-
expect(getName(test_case.input)).toBe(test_case.expected);
13+
expect(getName(test_case.input)).toBe(test_case.expected);
1414
}
1515
});
1616

@@ -21,10 +21,10 @@ describe("all tests", () => {
2121
{ input: "smith.John@gmail.com", expected: "smithjohn@gmail.com" },
2222
{ input: "smithjohn@gMail.com", expected: "smithjohn@gmail.com" },
2323
{ input: "smith.john@outlook.com", expected: "smith.john@outlook.com" },
24-
]
24+
];
2525

2626
for (let test_case of test_data) {
2727
expect(parseEmailForComparing(test_case.input)).toBe(test_case.expected);
2828
}
29-
})
29+
});
3030
});

components/expired-members-remover/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"license": "MIT",
1313
"devDependencies": {
1414
"cross-env": "^7.0.2",
15-
"dotenv": "^8.2.0",
16-
"jest": "^26.1.0",
15+
"dotenv": "^16.0.0",
16+
"jest": "^27.5.1",
1717
"supertest": "^6.0.1"
1818
},
1919
"dependencies": {
2020
"@google-cloud/secret-manager": "^3.10.0",
2121
"@sendgrid/mail": "^7.4.4",
2222
"google-spreadsheet": "^3.0.11",
23-
"googleapis": "^74.2.0"
23+
"googleapis": "^100.0.0"
2424
},
2525
"jest": {
2626
"testEnvironment": "node",

components/membership-form-backend-trigger/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ module.exports.main = async (req, res) => {
99
console.log("Received request.");
1010

1111
console.log("Publishing request body to Pub/Sub...");
12-
await pubSubClient
13-
.topic(TOPIC_NAME)
14-
.publish(Buffer.from(JSON.stringify(req.body), "utf8"));
12+
await pubSubClient.topic(TOPIC_NAME).publish(
13+
Buffer.from(
14+
JSON.stringify({
15+
additionalInfo: { ip: req.ip, ...req.headers },
16+
...req.body,
17+
}),
18+
"utf8"
19+
)
20+
);
1521

1622
console.log("Redirecting to welcome page...");
1723
// We don't use res.redirect since that would redirect only the iFrame not the entire page

components/membership-form-backend/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,8 @@ const validatePayment = async (orderID, payPalClient, expectedPayment) => {
230230
);
231231

232232
if (expectedPayment !== authorizedPayment) {
233-
console.log(
234-
`Received payment (${authorizedPayment}$) doesn't match expected payment (${expectedPayment}$).`
235-
);
236-
throw new Error("Received payment doesn't match expected payment.");
233+
throw new Error(`Received payment (${authorizedPayment}$) doesn't match expected payment (${expectedPayment}$).
234+
The webmaster should reach out to the member to help them retry the payment.`);
237235
}
238236
};
239237

components/membership-form-backend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
"devDependencies": {
1414
"cross-env": "^7.0.2",
1515
"express": "^4.17.1",
16-
"jest": "^26.1.0",
16+
"jest": "^27.5.1",
1717
"supertest": "^6.0.1"
1818
},
1919
"dependencies": {
2020
"@google-cloud/secret-manager": "^3.10.0",
2121
"@paypal/checkout-server-sdk": "^1.0.2",
2222
"@sendgrid/mail": "^7.4.4",
2323
"google-spreadsheet": "^3.0.11",
24-
"googleapis": "^74.2.0",
24+
"googleapis": "^100.0.0",
2525
"moment": "^2.29.2"
2626
},
2727
"jest": {

components/membership-form-frontend/script.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ function toPaymentTab() {
3535
},
3636
createOrder: function (data, actions) {
3737
const typeDropdown = document.getElementById("membership_type");
38-
const value = PRICING[
39-
typeDropdown.options[typeDropdown.selectedIndex].value
40-
].toString();
38+
const value =
39+
PRICING[
40+
typeDropdown.options[typeDropdown.selectedIndex].value
41+
].toString();
4142
return actions.order.create({
4243
purchase_units: [{ amount: { value } }],
4344
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"components/*"
1616
],
1717
"devDependencies": {
18-
"@google-cloud/functions-framework": "^2.1.0",
18+
"@google-cloud/functions-framework": "^3.1.0",
1919
"firebase-tools": "^10.0.1",
2020
"prettier": "^2.1.1"
2121
}

0 commit comments

Comments
 (0)