: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 { DateTime } from 'luxon'
import { TemplateTester } from '../../test/test-helpers'
import { template } from './email.template'
describe('email template', () => {
const tester = new TemplateTester(template)
beforeEach(async () => {
await tester.beforeEach()
const fixedTime = DateTime.fromISO('2025-01-01T00:00:00Z').toJSDate()
jest.spyOn(Date, 'now').mockReturnValue(fixedTime.getTime())
})
it('should invoke the function', async () => {
const response = await tester.invoke(
{
email: {
to: {
email: '{{ person.properties.email }}',
name: '{{ person.name }}',
},
from: {
integrationId: 1,
},
subject: 'PostHog Notification',
text: '',
html: '',
},
debug: false,
},
{
event: {
properties: {
$lib_version: '1.0.0',
},
},
}
)
expect(response.error).toBeUndefined()
expect(response.finished).toEqual(false)
expect(response.invocation.queueParameters).toMatchInlineSnapshot(`
{
"from": {
"integrationId": 1,
},
"html": "",
"subject": "PostHog Notification",
"text": "",
"to": {
"email": "[email protected]",
"name": "person-name",
},
"type": "email",
}
`)
})
it('should pass cc and bcc strings through to queue parameters', async () => {
const response = await tester.invoke(
{
email: {
to: {
email: '[email protected]',
name: '',
},
from: {
integrationId: 1,
},
cc: '[email protected], [email protected]',
bcc: '[email protected]',
subject: 'Test',
text: '',
html: '',
},
debug: false,
},
{}
)
expect(response.error).toBeUndefined()
expect(response.invocation.queueParameters).toMatchObject({
type: 'email',
cc: '[email protected], [email protected]',
bcc: '[email protected]',
})
})
})