/** * forms.emailsInTransaction: true — the e-mails of a form go out inside the submission's transaction, as * before 1.17.0. Postgres only (IPAL_TEST_POSTGRES_URI); its own file, because one test process pushes the * schema of one Payload (test/transactionPool.test.ts has the default). */ import { describe, expect, test, vi } from 'vitest' import { submitForm } from '../src/modules/forms/submitForm.js' import { site } from './transactionPoolSite.js' vi.mock('server-only', () => ({})) describe.runIf(Boolean(process.env.IPAL_TEST_POSTGRES_URI))('Postgres, forms.emailsInTransaction: true', () => { test('forms.emailsInTransaction: true sends inside the transaction, as before 1.17.0', async () => { const other = await site('txpoolin', { emailsInTransaction: true }) const send = vi.spyOn(other.payload, 'sendEmail') const seen: number[] = [] send.mockImplementation(async () => { seen.push((await other.payload.count({ collection: 'form-submissions' as never })).totalDocs) return { sent: true } }) try { const result = await submitForm({ data: { email: 'v@example.org', message: 'm' }, formId: other.formId, maxPerMinute: 0, payload: other.payload }) expect(result).toMatchObject({ success: true }) expect(seen).toEqual([0, 0]) // not committed yet when the e-mails went out } finally { send.mockRestore() await other.payload.destroy() } }, 60_000) })