:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { EmailRecipients, SuppressedRecipientsResult, removeSuppressedRecipients } from './suppressed-recipients'
describe('removeSuppressedRecipients', () => {
const suppressed = new Set(['[email protected]', '[email protected]'])
const isSuppressed = (email: string): Promise<boolean> => Promise.resolve(suppressed.has(email))
it.each<[string, EmailRecipients, SuppressedRecipientsResult]>([
[
'leaves the recipients unchanged when nobody is suppressed',
{ to: { email: '[email protected]' }, cc: '[email protected]', bcc: '[email protected]' },
{ skip: false, cc: '[email protected]', bcc: '[email protected]', removed: [] },
],
[
'removes suppressed cc and bcc entries and keeps the original form of the others',
{
to: { email: '[email protected]' },
cc: '"B" <[email protected]>, "Gone" <[email protected]>',
bcc: '[email protected]',
},
{
skip: false,
cc: '"B" <[email protected]>',
bcc: '',
removed: ['[email protected]', '[email protected]'],
},
],
[
'removes a suppressed bracketed address that has text after it',
{ to: { email: '[email protected]' }, cc: '"Gone" <[email protected]> (old), [email protected]' },
{ skip: false, cc: '[email protected]', bcc: '', removed: ['[email protected]'] },
],
[
'checks the mailbox, not an address inside a quoted display name',
{
to: { email: '[email protected]' },
cc: '"Bob <[email protected]>" <[email protected]>, "Doe, Jane" <[email protected]>',
},
{ skip: false, cc: '"Doe Jane" <[email protected]>', bcc: '', removed: ['[email protected]'] },
],
[
'checks a quoted local part unquoted and keeps the quotes for delivery',
{ to: { email: '[email protected]' }, cc: '"bounced"@example.com, "john doe"@example.com' },
{ skip: false, cc: '"john doe"@example.com', bcc: '', removed: ['[email protected]'] },
],
[
'checks a quoted to address unquoted',
{ to: { email: '"bounced"@example.com' }, cc: '[email protected]' },
{
skip: false,
promotedTo: { email: '[email protected]' },
cc: '',
bcc: '',
removed: ['[email protected]'],
},
],
[
'promotes the first deliverable cc address when to is suppressed',
{
to: { email: '[email protected]' },
cc: '[email protected], "Admin B" <[email protected]>, [email protected]',
},
{
skip: false,
promotedTo: { email: '[email protected]', name: 'Admin B' },
cc: '[email protected]',
bcc: '',
removed: ['[email protected]', '[email protected]'],
},
],
[
'skips when to is suppressed and only bcc addresses are left',
{ to: { email: '[email protected]' }, bcc: '[email protected]' },
{ skip: true, removed: ['[email protected]'] },
],
[
'does not skip when there is no to address to check',
{ to: { email: '' }, cc: '[email protected]' },
{ skip: false, cc: '[email protected]', bcc: undefined, removed: [] },
],
])('%s', async (_name, recipients, expected) => {
expect(await removeSuppressedRecipients(recipients, isSuppressed)).toEqual(expected)
})
})