ultisuite-backend/internal/mail/sanitize/mjml_test.go
2026-06-04 00:12:11 +02:00

59 lines
2.9 KiB
Go

package sanitize
import (
"strings"
"testing"
)
func TestSanitizeHTML_MJMLNewsletter(t *testing.T) {
// Real MJML pattern from Pennylane newsletter
in := `<!doctype html><html><head><style type="text/css">
#outlook a { padding: 0; }
body { margin: 0; padding: 0; }
table, td { border-collapse: collapse; }
.mj-column-per-100 { width:100% !important; max-width:100%; }
</style></head><body style="word-spacing:normal;background-color:#f8f9fa;">
<div style="background-color:#f8f9fa;">
<div style="background:white;background-color:white;margin:0px auto;max-width:600px;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" align="center" style="background:white;width:100%;">
<tbody><tr><td style="direction:ltr;font-size:0px;padding:10px 0;text-align:center;">
<div class="mj-outlook-group-fix mj-column-per-100" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" role="presentation" width="100%" style="vertical-align:top;">
<tbody><tr><td align="center" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-family:sans-serif;font-size:16px;font-weight:400;line-height:24px;text-align:center;color:#000000;">
<img src="https://assets.pennylane.com/logo.png" alt="Pennylane logo" style="max-height:34px;max-width:100%" />
</div></td></tr></tbody></table></div>
</td></tr></tbody></table></div>
<div style="background:white;margin:0px auto;max-width:600px;">
<table border="0" cellpadding="0" cellspacing="0" align="center" style="background:white;width:100%;">
<tbody><tr><td style="direction:ltr;font-size:0px;padding:10px 0;text-align:center;">
<div class="mj-column-per-100" style="font-size:0px;text-align:left;direction:ltr;display:inline-block;vertical-align:top;width:100%;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="vertical-align:top;">
<tbody><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-size:22px;font-weight:600;line-height:32px;color:#006666;">5 notifications non lues</div>
</td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-size:14px;line-height:24px;color:#000000;">Bonjour Eliott,</div>
</td></tr><tr><td align="left" style="font-size:0px;padding:10px 25px;word-break:break-word;">
<div style="font-size:14px;line-height:24px;color:#000000;">Vous avez 5 notifications non lues</div>
</td></tr></tbody></table></div>
</td></tr></tbody></table></div>
</div></body></html>`
out := SanitizeHTML(in)
checks := []string{
"Pennylane logo",
"5 notifications non lues",
"Bonjour Eliott",
"Vous avez 5 notifications",
}
for _, want := range checks {
if !strings.Contains(out, want) {
t.Errorf("MJML content %q missing from output.\nOutput: %s", want, out)
}
}
if strings.TrimSpace(out) == "" {
t.Fatal("sanitizer produced empty output for MJML newsletter")
}
}