fix(crm): pre-event reminder passes raw event_date (fixes "Invalid Date" in the email)

composePayload pre-formatted event_date to DD.MM.YYYY, but emailProcessor runs
date variables through formatDate(value, language) — new Date("25.06.2026")
can't parse → the email rendered "Invalid Date". Pass the raw event_date and let
the processor localise it, matching the expiry mailer's contract. Pre-existing
in the migration-143 composePayload (dormant while the legacy pass was gated
off); surfaced once the pre_event_email flow ran.
This commit is contained in:
Luca
2026-06-25 19:22:04 +02:00
parent 675e41a2f7
commit 250b240337
2 changed files with 15 additions and 9 deletions
@@ -415,6 +415,16 @@ describe('workflow engine', () => {
expect(await _internal.resolveTemplateKey('zzznotype', 'promo_')).toBe('promo_default'); expect(await _internal.resolveTemplateKey('zzznotype', 'promo_')).toBe('promo_default');
}); });
test('pre-event payload passes the RAW event_date (processor formats it — no "Invalid Date")', async () => {
const { _internal } = require('../../src/services/eventReminderService');
const p = _internal.composePayload({
event: { id: 1, event_name: 'X', event_date: '2026-06-25', customer_name: 'A' },
recipientEmail: '[email protected]', daysBefore: 2, businessName: 'Biz',
});
expect(p.event_date).toBe('2026-06-25'); // raw, not pre-formatted DD.MM.YYYY
expect(p.event_date).not.toMatch(/invalid/i);
});
test('webhook action enqueues a delivery for a configured subscription (full pipeline)', async () => { test('webhook action enqueues a delivery for a configured subscription (full pipeline)', async () => {
const webhook = engine.registry.getAction('webhook'); const webhook = engine.registry.getAction('webhook');
expect(typeof webhook).toBe('function'); // registered — no longer a silent no-op expect(typeof webhook).toBe('function'); // registered — no longer a silent no-op
+5 -9
View File
@@ -103,18 +103,14 @@ function composePayload({ event, recipientEmail, daysBefore, businessName }) {
|| event.host_name || event.host_name
|| recipientEmail || recipientEmail
|| ''; || '';
// Event date formatted DD.MM.YYYY here for simplicity; the rendered // Pass the RAW event_date — emailProcessor.processTemplate runs it through
// email may further re-locale via the template engine when locale- // formatDate(value, recipientLanguage). Pre-formatting it (e.g. DD.MM.YYYY)
// aware formatters are introduced. // makes the processor's new Date(...) reparse fail → "Invalid Date". Same
const ed = event.event_date instanceof Date ? event.event_date : new Date(event.event_date); // contract the expiry mailer uses.
const day = String(ed.getUTCDate()).padStart(2, '0');
const month = String(ed.getUTCMonth() + 1).padStart(2, '0');
const year = ed.getUTCFullYear();
const eventDateFormatted = `${day}.${month}.${year}`;
return { return {
customer_name: customerName, customer_name: customerName,
event_name: event.event_name || `Event #${event.id}`, event_name: event.event_name || `Event #${event.id}`,
event_date: eventDateFormatted, event_date: event.event_date || '',
event_type: event.event_type || '', event_type: event.event_type || '',
days_before: daysBefore, days_before: daysBefore,
business_name: businessName || '', business_name: businessName || '',