Skip to content

Commit

Permalink
fix(mail.service): updated to cc rather than send individual mail
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Aug 5, 2021
1 parent 82aa6ed commit 2240016
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
36 changes: 19 additions & 17 deletions src/app/services/mail/__tests__/mail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1257,11 +1257,11 @@ describe('mail.service', () => {

const MOCK_FORM: IPopulatedForm = {
permissionList: [
{ email: MOCK_VALID_EMAIL },
{ email: MOCK_VALID_EMAIL_2 },
{ email: MOCK_VALID_EMAIL_3 },
],
admin: {
email: MOCK_VALID_EMAIL_3,
email: MOCK_VALID_EMAIL,
},
title: MOCK_FORM_TITLE,
_id: MOCK_FORM_ID,
Expand All @@ -1277,16 +1277,17 @@ describe('mail.service', () => {
} as unknown as IPopulatedForm

const generateExpectedMailOptions = async (
count: number,
emailRecipients: string | string[],
admin: string,
collaborators: string | string[],
) => {
const result = await MailUtils.generateSmsVerificationDisabledHtml({
formTitle: MOCK_FORM_TITLE,
formLink: `${MOCK_APP_URL}/${MOCK_FORM_ID}`,
smsVerificationLimit: smsConfig.smsVerificationLimit,
}).map((emailHtml) => {
return {
to: emailRecipients,
to: admin,
cc: collaborators,
from: MOCK_SENDER_STRING,
html: emailHtml,
subject: '[FormSG] SMS Verification - Free Tier Limit Reached',
Expand All @@ -1306,11 +1307,10 @@ describe('mail.service', () => {
const actualResult = await mailService.sendSmsVerificationDisabledEmail(
MOCK_FORM,
)
const expectedMailOptions = await generateExpectedMailOptions(1000, [
const expectedMailOptions = await generateExpectedMailOptions(
MOCK_VALID_EMAIL,
MOCK_VALID_EMAIL_2,
MOCK_VALID_EMAIL_3,
])
[MOCK_VALID_EMAIL_2, MOCK_VALID_EMAIL_3],
)

// Assert
expect(actualResult._unsafeUnwrap()).toEqual(true)
Expand Down Expand Up @@ -1362,11 +1362,11 @@ describe('mail.service', () => {

const MOCK_FORM: IPopulatedForm = {
permissionList: [
{ email: MOCK_VALID_EMAIL },
{ email: MOCK_VALID_EMAIL_2 },
{ email: MOCK_VALID_EMAIL_3 },
],
admin: {
email: MOCK_VALID_EMAIL_3,
email: MOCK_VALID_EMAIL,
},
title: MOCK_FORM_TITLE,
_id: MOCK_FORM_ID,
Expand All @@ -1383,7 +1383,8 @@ describe('mail.service', () => {

const generateExpectedMailOptions = async (
count: number,
emailRecipients: string | string[],
admin: string,
collaborators: string | string[],
) => {
const result = await MailUtils.generateSmsVerificationWarningHtml({
formTitle: MOCK_FORM_TITLE,
Expand All @@ -1392,7 +1393,8 @@ describe('mail.service', () => {
smsVerificationLimit: smsConfig.smsVerificationLimit,
}).map((emailHtml) => {
return {
to: emailRecipients,
to: admin,
cc: collaborators,
from: MOCK_SENDER_STRING,
html: emailHtml,
subject: '[FormSG] SMS Verification - Free Tier Limit Alert',
Expand All @@ -1413,11 +1415,11 @@ describe('mail.service', () => {
MOCK_FORM,
1000,
)
const expectedMailOptions = await generateExpectedMailOptions(1000, [
const expectedMailOptions = await generateExpectedMailOptions(
1000,
MOCK_VALID_EMAIL,
MOCK_VALID_EMAIL_2,
MOCK_VALID_EMAIL_3,
])
[MOCK_VALID_EMAIL_2, MOCK_VALID_EMAIL_3],
)

// Assert
expect(actualResult._unsafeUnwrap()).toEqual(true)
Expand Down
14 changes: 6 additions & 8 deletions src/app/services/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,11 @@ export class MailService {
}

return generateSmsVerificationDisabledHtml(htmlData).andThen((mailHtml) => {
const emailRecipients = form.permissionList
.map(({ email }) => email)
.concat(form.admin.email)
const formCollaborators = form.permissionList.map(({ email }) => email)

const mailOptions: MailOptions = {
to: emailRecipients,
to: form.admin.email,
cc: formCollaborators,
from: this.#senderFromString,
html: mailHtml,
subject: '[FormSG] SMS Verification - Free Tier Limit Reached',
Expand Down Expand Up @@ -634,12 +633,11 @@ export class MailService {
}

return generateSmsVerificationWarningHtml(htmlData).andThen((mailHtml) => {
const emailRecipients = form.permissionList
.map(({ email }) => email)
.concat(form.admin.email)
const formCollaborators = form.permissionList.map(({ email }) => email)

const mailOptions: MailOptions = {
to: emailRecipients,
to: form.admin.email,
cc: formCollaborators,
from: this.#senderFromString,
html: mailHtml,
subject: '[FormSG] SMS Verification - Free Tier Limit Alert',
Expand Down

0 comments on commit 2240016

Please sign in to comment.