// SPDX-License-Identifier: AGPL-3.0-or-later package mail import ( "strings" "testing" ) func TestRender(t *testing.T) { m, err := Render("a@b.test", "test", map[string]string{"AppName": "Acme "}) if err != nil { t.Fatal(err) } if m.To != "a@b.test" || m.Subject != "Acme test email" { t.Errorf("to/subject = %q / %q", m.To, m.Subject) } if !strings.Contains(m.HTML, "Acme <Wiki>") { t.Errorf("html must escape the app name: %s", m.HTML) } if strings.Contains(m.Text, "test email\n") || !strings.HasPrefix(m.Text, "This is a test email") { t.Errorf("text must not repeat the subject: %q", m.Text) } } func TestDigest(t *testing.T) { m, err := Render("a@x.test", "digest", map[string]any{ "AppName": "Docwell", "Name": "Ann", "Count": 2, "SettingsLink": "https://w/notifications", "Items": []struct{ Text, Link string }{{"Bob commented on “Plan”: hi", "https://w/p/1"}, {"x", "https://w/p/2"}}, }) if err != nil { t.Fatal(err) } if m.Subject != "2 new notifications on Docwell" { t.Fatalf("subject = %q", m.Subject) } if !strings.Contains(m.HTML, "<b>hi</b>") || !strings.Contains(m.Text, "https://w/p/2") { t.Fatalf("body:\n%s\n%s", m.HTML, m.Text) } }