package mailer import ( "strings" "testing" ) // The renderer and the embedded design file are one unit: these tests pin // the anchors so a template edit that drops a marker fails loudly instead // of silently shipping unfilled placeholders. func TestRenderFull(t *testing.T) { html, err := Render("Reset your Superbrain password", Content{ Preheader: "Choose a new password.", Headline: "Reset your password", FirstName: "Alice", Body: "First paragraph.\nSecond paragraph.", CTAURL: "https://superbrain.test/reset-password?token=abc", CTALabel: "Choose a new password", Note: "The link expires in 30 minutes.", SignOff: "Cheers,", PreferencesURL: "https://superbrain.test/settings", UnsubscribeURL: "https://superbrain.test/unsubscribe", HelpURL: "https://superbrain.test/help", CompanyAddress: "1 Example Way, Testville", }) if err != nil { t.Fatal(err) } for _, want := range []string{ "Reset your password", "Hi Alice,", "First paragraph.", "Second paragraph.", "Choose a new password", "https://superbrain.test/reset-password?token=abc", "v:roundrect", "If the button doesn't work", // Outlook fallback + plain link "The link expires in 30 minutes.", "Cheers,", "The Superbrain team", "Email preferences", "Unsubscribe", "Help center", "1 Example Way, Testville", "Choose a new password.", // preheader } { if !strings.Contains(html, want) { t.Errorf("rendered mail missing %q", want) } } if strings.Contains(html, "{{") { t.Errorf("unfilled placeholder remains:\n%s", html) } } func TestRenderMinimal(t *testing.T) { html, err := Render("Bookmark due: Due soon", Content{ Headline: "Bookmark due: Due soon", Body: "Due soon is due in 6 hours.", }) if err != nil { t.Fatal(err) } if strings.Contains(html, "{{") { t.Errorf("unfilled placeholder remains:\n%s", html) } // Optional sections are removed, not stubbed. for _, absent := range []string{ "v:roundrect", "If the button doesn't work", // CTA + fallback rows `"`, Content{ Headline: ``, FirstName: `Ann", "Ann