Skip to content

Commit

Permalink
chore: remove overtested test cases
Browse files Browse the repository at this point in the history
fix: failing stringify
  • Loading branch information
KenLSM committed Oct 29, 2024
1 parent c7e3cda commit 365f410
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`mail.service sendBounceNotification should send permanent bounce notification successfully 1`] = `
[MockFunction] {
"calls": [
[
{
"from": "mockApp <[email protected]>",
"headers": {
"X-Formsg-Email-Type": "Admin (bounce notification)",
"X-Formsg-Form-ID": "mockFormId",
},
"html": "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/></head><body><p style="font-size:14px;line-height:24px;margin:16px 0">Dear form admins(s),</p><p style="font-size:14px;line-height:24px;margin:16px 0">We’re reaching out urgently regarding your FormSG form You are all individuals!(mockApp.example.com/mockFormId). Responses to the following recipient(s) could not be delivered: [email protected], [email protected]. This was likely due to their mailbox being full.</p><p style="font-size:14px;line-height:24px;margin:16px 0">Please refer to our <a href="https://go.gov.sg/formsg-guide-bounces" style="color:#067df7;text-decoration:none" target="_blank">guide</a> for next steps on how to resolve this issue.</p><p style="font-size:14px;line-height:24px;margin:16px 0">The mockApp Support Team</p></body></html>",
"subject": "[Urgent] FormSG Response Delivery Failure / Bounce",
"to": [
"[email protected]",
"[email protected]",
],
},
],
],
"results": [
[
[
{
"type": "return",
"value": Promise {},
"from": "mockApp <[email protected]>",
"headers": {
"X-Formsg-Email-Type": "Admin (bounce notification)",
"X-Formsg-Form-ID": "mockFormId",
},
"html": "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/></head><body><p style="font-size:14px;line-height:24px;margin:16px 0">Dear form admins(s),</p><p style="font-size:14px;line-height:24px;margin:16px 0">We’re reaching out urgently regarding your FormSG form You are all individuals!(mockApp.example.com/mockFormId). Responses to the following recipient(s) could not be delivered: [email protected], [email protected]. This was likely due to their mailbox being full.</p><p style="font-size:14px;line-height:24px;margin:16px 0">Please refer to our <a href="https://go.gov.sg/formsg-guide-bounces" style="color:#067df7;text-decoration:none" target="_blank">guide</a> for next steps on how to resolve this issue.</p><p style="font-size:14px;line-height:24px;margin:16px 0">The mockApp Support Team</p></body></html>",
"subject": "[Urgent] FormSG Response Delivery Failure / Bounce",
"to": [
"[email protected]",
"[email protected]",
],
},
],
}
]
`;

exports[`mail.service sendBounceNotification should send transient bounce notification successfully 1`] = `
[MockFunction] {
"calls": [
[
{
"from": "mockApp <[email protected]>",
"headers": {
"X-Formsg-Email-Type": "Admin (bounce notification)",
"X-Formsg-Form-ID": "mockFormId",
},
"html": "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/></head><body><p style="font-size:14px;line-height:24px;margin:16px 0">Dear form admins(s),</p><p style="font-size:14px;line-height:24px;margin:16px 0">We’re reaching out urgently regarding your FormSG form You are all individuals!(mockApp.example.com/mockFormId). Responses to the following recipient(s) could not be delivered: [email protected], [email protected]. This was likely due to their mailbox being full.</p><p style="font-size:14px;line-height:24px;margin:16px 0">Please refer to our <a href="https://go.gov.sg/formsg-guide-bounces" style="color:#067df7;text-decoration:none" target="_blank">guide</a> for next steps on how to resolve this issue.</p><p style="font-size:14px;line-height:24px;margin:16px 0">The mockApp Support Team</p></body></html>",
"subject": "[Urgent] FormSG Response Delivery Failure / Bounce",
"to": [
"[email protected]",
"[email protected]",
],
},
],
],
"results": [
[
[
{
"type": "return",
"value": Promise {},
"from": "mockApp <[email protected]>",
"headers": {
"X-Formsg-Email-Type": "Admin (bounce notification)",
"X-Formsg-Form-ID": "mockFormId",
},
"html": "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html dir="ltr" lang="en"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/></head><body><p style="font-size:14px;line-height:24px;margin:16px 0">Dear form admins(s),</p><p style="font-size:14px;line-height:24px;margin:16px 0">We’re reaching out urgently regarding your FormSG form You are all individuals!(mockApp.example.com/mockFormId). Responses to the following recipient(s) could not be delivered: [email protected], [email protected]. This was likely due to their mailbox being full.</p><p style="font-size:14px;line-height:24px;margin:16px 0">Please refer to our <a href="https://go.gov.sg/formsg-guide-bounces" style="color:#067df7;text-decoration:none" target="_blank">guide</a> for next steps on how to resolve this issue.</p><p style="font-size:14px;line-height:24px;margin:16px 0">The mockApp Support Team</p></body></html>",
"subject": "[Urgent] FormSG Response Delivery Failure / Bounce",
"to": [
"[email protected]",
"[email protected]",
],
},
],
}
]
`;
12 changes: 3 additions & 9 deletions src/app/services/mail/__tests__/mail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,8 @@ describe('mail.service', () => {
html: expect.stringMatching(MOCK_FORM_ID),
}),
)
expect(sendMailSpy).toMatchSnapshot()

expect(sendMailSpy.mock.calls).toMatchSnapshot()
})

it('should send transient bounce notification successfully', async () => {
Expand Down Expand Up @@ -1239,7 +1240,7 @@ describe('mail.service', () => {
html: expect.stringMatching(MOCK_FORM_ID),
}),
)
expect(sendMailSpy).toMatchSnapshot()
expect(sendMailSpy.mock.calls).toMatchSnapshot()
})

it('should reject with error when email is invalid', async () => {
Expand Down Expand Up @@ -1280,16 +1281,13 @@ describe('mail.service', () => {
formId: MOCK_FORM_ID,
formTitle: MOCK_FORM_TITLE,
})
const expectedArgs = await generateExpectedArg(MOCK_BOUNCE_TYPE)

// Assert
expect(actualResult._unsafeUnwrap()).toEqual(true)
// Check arguments passed to sendNodeMail
// Should have been called two times since it rejected the first one and
// resolved
expect(sendMailSpy).toHaveBeenCalledTimes(2)
expect(sendMailSpy).toHaveBeenNthCalledWith(1, expectedArgs)
expect(sendMailSpy).toHaveBeenNthCalledWith(2, expectedArgs)
})

it('should autoretry MOCK_RETRY_COUNT times and return error when all retries fail with 4xx errors', async () => {
Expand All @@ -1308,7 +1306,6 @@ describe('mail.service', () => {
formId: MOCK_FORM_ID,
formTitle: MOCK_FORM_TITLE,
})
const expectedArgs = await generateExpectedArg(MOCK_BOUNCE_TYPE)

// Assert
const actualError = actualResult._unsafeUnwrapErr()
Expand All @@ -1317,7 +1314,6 @@ describe('mail.service', () => {
// Check arguments passed to sendNodeMail
// Should have been called MOCK_RETRY_COUNT + 1 times
expect(sendMailSpy).toHaveBeenCalledTimes(MOCK_RETRY_COUNT + 1)
expect(sendMailSpy).toHaveBeenCalledWith(expectedArgs)
})

it('should stop autoretrying when the returned error is not a 4xx error', async () => {
Expand All @@ -1339,7 +1335,6 @@ describe('mail.service', () => {
formId: MOCK_FORM_ID,
formTitle: MOCK_FORM_TITLE,
})
const expectedArgs = await generateExpectedArg(MOCK_BOUNCE_TYPE)

// Assert
const actualError = actualResult._unsafeUnwrapErr()
Expand All @@ -1350,7 +1345,6 @@ describe('mail.service', () => {
// Should retry two times and stop since the second rejected value is
// non-4xx error.
expect(sendMailSpy).toHaveBeenCalledTimes(2)
expect(sendMailSpy).toHaveBeenCalledWith(expectedArgs)
})
})

Expand Down

0 comments on commit 365f410

Please sign in to comment.