diff --git a/packages/backend/src/apps/postman/__tests__/common/parameters.test.ts b/packages/backend/src/apps/postman/__tests__/common/parameters.test.ts index 0158e214d..cab5374cd 100644 --- a/packages/backend/src/apps/postman/__tests__/common/parameters.test.ts +++ b/packages/backend/src/apps/postman/__tests__/common/parameters.test.ts @@ -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 @@ -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', + ) + }, + ) }) diff --git a/packages/backend/src/apps/postman/common/parameters.ts b/packages/backend/src/apps/postman/common/parameters.ts index 78b99d8ed..d6b6aa19e 100644 --- a/packages/backend/src/apps/postman/common/parameters.ts +++ b/packages/backend/src/apps/postman/common/parameters.ts @@ -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') {