Skip to content

Commit

Permalink
feat: add formurl to otp email
Browse files Browse the repository at this point in the history
  • Loading branch information
KenLSM committed Dec 13, 2024
1 parent e300ebf commit ad47c52
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ Default.args = {
otp: '123456',
minutesToExpiry: 30,
appName: 'FormSG',
formUrl: 'https://form.gov.sg/645b5f5372deb40012fe98123',
}
2 changes: 1 addition & 1 deletion src/app/modules/verification/verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ const sendOtpForField = (
: errAsync(new MalformedParametersError('Field id not present'))
case BasicField.Email:
// call email - it should validate the recipient
return MailService.sendVerificationOtp(recipient, otp, otpPrefix)
return MailService.sendVerificationOtp(recipient, otp, otpPrefix, formId)
default:
return errAsync(new NonVerifiedFieldTypeError(fieldType))
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/services/mail/__tests__/mail.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ describe('mail.service', () => {

describe('sendVerificationOtp', () => {
const MOCK_OTP = '123456'
const MOCK_FORM_ID = 'mockFormId'
const MOCK_FORM_URL = `${MOCK_APP_URL}/${MOCK_FORM_ID}`

const expectedArg = expect.objectContaining({
to: MOCK_VALID_EMAIL,
Expand All @@ -96,6 +98,7 @@ describe('mail.service', () => {
MOCK_VALID_EMAIL,
MOCK_OTP,
MOCK_OTP_PREFIX,
MOCK_FORM_URL,
)

// Assert
Expand All @@ -114,6 +117,7 @@ describe('mail.service', () => {
invalidEmail,
MOCK_OTP,
MOCK_OTP_PREFIX,
MOCK_FORM_URL,
)

// Assert
Expand All @@ -138,6 +142,7 @@ describe('mail.service', () => {
MOCK_VALID_EMAIL,
MOCK_OTP,
MOCK_OTP_PREFIX,
MOCK_FORM_URL,
)

// Assert
Expand All @@ -162,6 +167,7 @@ describe('mail.service', () => {
MOCK_VALID_EMAIL,
MOCK_OTP,
MOCK_OTP_PREFIX,
MOCK_FORM_URL,
)

// Assert
Expand Down Expand Up @@ -192,6 +198,7 @@ describe('mail.service', () => {
MOCK_VALID_EMAIL,
MOCK_OTP,
MOCK_OTP_PREFIX,
MOCK_FORM_URL,
)

// Assert
Expand Down
5 changes: 5 additions & 0 deletions src/app/services/mail/mail.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,20 @@ export class MailService {
recipient: string,
otp: string,
otpPrefix: string,
formId: string,
): ResultAsync<true, MailSendError> => {
const minutesToExpiry = Math.floor(HASH_EXPIRE_AFTER_SECONDS / 60)

const formUrl = this.#appUrl + `/${formId}`

const htmlData: EmailAddressVerificationOtpHtmlData = {
appName: this.#appName,
minutesToExpiry,
otp,
otpPrefix,
formUrl,
}

const generatedHtml = fromPromise(
render(EmailAddressVerificationOtp(htmlData)),
(e) => {
Expand Down
9 changes: 7 additions & 2 deletions src/app/views/templates/EmailAddressVerificationOtp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ export type EmailAddressVerificationOtpHtmlData = {
otp: string
minutesToExpiry: number
appName: string
formUrl: string
}

export const EmailAddressVerificationOtp = ({
otpPrefix,
otp,
minutesToExpiry,
appName,
formUrl,
}: EmailAddressVerificationOtpHtmlData): JSX.Element => {
return (
<Html>
<Head />
<Body>
<Text>You are currently submitting a form on {appName}.</Text>
<Text>
You are trying to verify your email address on the following form:{' '}
<a href={formUrl}>{formUrl}</a>.
</Text>
<Text>
Your OTP is {otpPrefix}-<b>{otp}</b>. It will expire in{' '}
{minutesToExpiry} minutes. Please use this to verify your submission.
{minutesToExpiry} minutes.
</Text>
<Text>
Never share your OTP with anyone else. If you did not request this
Expand Down

0 comments on commit ad47c52

Please sign in to comment.