Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Merge pull request #109 from netlify/ljt/better-logging-of-progress
Browse files Browse the repository at this point in the history
  • Loading branch information
lemusthelroy authored Nov 15, 2022
2 parents 9510e82 + 583e757 commit a2a5a8e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/handler/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ describe("Email handler", () => {

expect(response).toEqual({
statusCode: 200,
body: expect.stringContaining("Email successfully sent with sendgrid"),
body: expect.stringContaining("Email sent successfully using sendgrid"),
});
expect(mockSendgridSend).toHaveBeenCalledWith({
from: "[email protected]",
Expand Down Expand Up @@ -385,7 +385,7 @@ describe("Email handler", () => {

expect(response).toEqual({
statusCode: 200,
body: expect.stringContaining("Email successfully sent with mailgun"),
body: expect.stringContaining("Email sent successfully using mailgun"),
});
expect(mockMailgunCreate).toHaveBeenCalledWith("domain.com", {
from: "[email protected]",
Expand Down Expand Up @@ -417,7 +417,7 @@ describe("Email handler", () => {

expect(response).toEqual({
statusCode: 200,
body: expect.stringContaining("Email successfully sent with postmark"),
body: expect.stringContaining("Email sent successfully using postmark"),
});
expect(mockPostmarkSendEmail).toHaveBeenCalledWith({
From: "[email protected]",
Expand Down
30 changes: 21 additions & 9 deletions src/handler/mailer/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"Email successfully sent with sendgrid"',
body: expect.stringContaining("Email sent successfully using sendgrid"),
statusCode: 200,
});
});
Expand All @@ -65,7 +65,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"The email API provider sendgrid failed to process the request: 403 - some error message"',
body: expect.stringContaining(
"The email API provider sendgrid failed to process the request: 403 - some error message"
),
statusCode: 500,
});
});
Expand All @@ -86,7 +88,7 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"Email successfully sent with mailgun"',
body: expect.stringContaining("Email sent successfully using mailgun"),
statusCode: 200,
});
});
Expand All @@ -101,7 +103,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"Domain should be specified when using Mailgun email API"',
body: expect.stringContaining(
"Domain should be specified when using Mailgun email API"
),
statusCode: 400,
});
});
Expand All @@ -121,7 +125,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"The email API provider mailgun failed to process the request: 403 - some error message"',
body: expect.stringContaining(
"The email API provider mailgun failed to process the request: 403 - some error message"
),
statusCode: 500,
});
});
Expand All @@ -141,7 +147,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"The email API provider mailgun failed to process the request: 403 - some error message"',
body: expect.stringContaining(
"The email API provider mailgun failed to process the request: 403 - some error message"
),
statusCode: 500,
});
});
Expand All @@ -157,7 +165,7 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"Email successfully sent with postmark"',
body: expect.stringContaining("Email sent successfully using postmark"),
statusCode: 200,
});
});
Expand All @@ -173,7 +181,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"The email API provider postmark failed to process the request: 403 - Failed with status code: 123"',
body: expect.stringContaining(
"The email API provider postmark failed to process the request: 403 - Failed with status code: 123"
),
statusCode: 500,
});
});
Expand All @@ -186,7 +196,9 @@ describe("Mailer function", () => {
});

expect(result).toEqual({
body: '"The email API provider postmark failed to process the request: Some error"',
body: expect.stringContaining(
"The email API provider postmark failed to process the request: Some error"
),
statusCode: 500,
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/handler/mailer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const mailer = async ({
}
}
if (emailProvider === "sendgrid") {
console.log("Sending email using Sendgrid...");
console.log("Sending email using SendGrid...");
sendGrid.setApiKey(configuration.apiKey);

try {
Expand All @@ -123,16 +123,20 @@ const mailer = async ({
}

if (errorMessage !== undefined) {
console.error(
`Failed to send email with ${emailProvider}: ${errorMessage}`
);
return {
statusCode: 500,
body: JSON.stringify(
`The email API provider ${emailProvider} failed to process the request: ${errorMessage}`
),
};
}
console.log(`Email sent successfully using ${emailProvider}`);
return {
statusCode: 200,
body: JSON.stringify(`Email successfully sent with ${emailProvider}`),
body: JSON.stringify(`Email sent successfully using ${emailProvider}`),
};
}
};
Expand Down

0 comments on commit a2a5a8e

Please sign in to comment.