Skip to content

Commit

Permalink
PLU-388: Postman Max 50 recipients (#825)
Browse files Browse the repository at this point in the history
## Problem
Postman limits each email to have a maximum of 50 recipients (including
the primary recipient, CC recipients, and BCC recipients), but Plumber
does not implement this check.

## Solution
* Add validation on the list of CC recipient emails

**Improvements**:
- Add validation on the list of CC recipient emails and throw error
before attempting to call the Postman API.

## Before & After Screenshots

**BEFORE**:
NA

**AFTER**:
<img width="865" alt="Screenshot 2024-12-18 at 5 30 00 PM"
src="https://github.com/user-attachments/assets/5f82382e-ba04-4f3b-9c21-da8204b27c7f"
/>


## Tests
- [x] Existing emails can be sent correctly
- [x] Step error thrown when more than 49 recipients included in the CC
field
  • Loading branch information
kevinkim-ogp authored Dec 19, 2024
1 parent af9f51f commit 4d96b4a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { assert, beforeEach, describe, expect, it } from 'vitest'

import { transactionalEmailSchema } from '../../common/parameters'

function generateEmails(length: number) {
return Array.from({ length }, (_, i) => `user${i + 1}@example.com`).join(',')
}

describe('postman transactional email schema zod validation', () => {
let validPayload: Record<string, unknown>

Expand Down Expand Up @@ -155,4 +159,22 @@ describe('postman transactional email schema zod validation', () => {
expect(result.error?.errors[0].message).toEqual('Invalid CC emails')
},
)

it.each([
{ recipient: 10, cc: 50 },
{ recipient: 41, cc: 51 },
{ recipient: 50, cc: 52 },
{ recipient: 1, cc: 50 },
])(
'should fail if total number of emails in Recipient email(s) and CC recipient email(s) exceeds 50',
({ recipient, cc }) => {
validPayload.destinationEmail = generateEmails(recipient)
validPayload.destinationEmailCc = generateEmails(cc)
const result = transactionalEmailSchema.safeParse(validPayload)
assert(result.success === false)
expect(result.error?.errors[0].message).toEqual(
'The total number of CC recipient emails must not exceed 49',
)
},
)
})
8 changes: 8 additions & 0 deletions packages/backend/src/apps/postman/common/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ export const transactionalEmailSchema = z.object({
destinationEmailCc: z
.string()
.transform((value, ctx) => validateEmails(value, ctx, 'Invalid CC emails'))
/**
* NOTE: Postman limits a maximum of 50 recipients (including primary recipient and CC recipients)
* Currently, Plumber sends emails to the main recipient individually,
* hence a limit of 49 CC recipients is enforced.
*/
.refine((value) => value.length <= 49, {
message: 'The total number of CC recipient emails must not exceed 49',
})
.optional(),
replyTo: z.preprocess((value) => {
if (typeof value !== 'string') {
Expand Down

0 comments on commit 4d96b4a

Please sign in to comment.