diff --git a/backend/src/sponsorDocs/templates.ts b/backend/src/sponsorDocs/templates.ts index a1cf3b36..7f37604a 100644 --- a/backend/src/sponsorDocs/templates.ts +++ b/backend/src/sponsorDocs/templates.ts @@ -1676,9 +1676,10 @@ export function renderSponsorEmailDraft(options: { } if (options.template === 'podcast-episode-brief') { - const firstName = options.recipientName?.trim().split(/\s+/)[0]; + const guestName = options.recipientName?.trim() || options.sponsorName?.trim() || ''; + const firstName = guestName.split(/\s+/)[0]; const body = [ - firstName ? `Hi ${firstName},` : 'Hi ,', + firstName ? `Hi ${firstName},` : 'Hi there,', '', `Here is the episode brief with the structure and questions for ${pubDate}:`, '', diff --git a/backend/tests/podcast-doc-email.test.ts b/backend/tests/podcast-doc-email.test.ts index f4a1ac12..6c754782 100644 --- a/backend/tests/podcast-doc-email.test.ts +++ b/backend/tests/podcast-doc-email.test.ts @@ -15,6 +15,14 @@ describe('podcast doc emails', () => { assert.doesNotMatch(body, /Hi team|staff-only|Internal/); }); + it('falls back to the guest name on the doc, then to a neutral greeting, never a placeholder', () => { + const fromDoc = renderSponsorEmailDraft({ ...base, template: 'podcast-episode-brief' }).body; + assert.match(fromDoc, /^Hi Sofiia,/); + const neutral = renderSponsorEmailDraft({ ...base, sponsorName: null, template: 'podcast-episode-brief' }).body; + assert.match(neutral, /^Hi there,/); + assert.doesNotMatch(neutral, //); + }); + for (const template of ['podcast-guest-research', 'podcast-run-sheet'] as const) { it(`keeps staff wording for ${template}`, () => { const { body } = renderSponsorEmailDraft({ ...base, template });