Files
vantage-shared/mail/dispute_test.go
T
2026-09-10 13:21:04 +00:00

71 lines
2.0 KiB
Go

package mail
import (
"strings"
"testing"
"time"
)
func sampleNotice() DisputeNotice {
return DisputeNotice{
AccountName: "Smith & Sons",
DisputeID: "dsp_123",
Reason: "Breach of the terms of service",
CloudNames: []string{"smith-prod"},
SelfHosted: []SelfHostedNotice{{Name: "smith-dc", LicenceExpires: time.Date(2026, 11, 2, 0, 0, 0, 0, time.UTC)}},
DisputeEmail: "disputes@vantage.example",
DisputeBy: time.Date(2026, 9, 17, 10, 0, 0, 0, time.UTC),
}
}
var disputeTemplates = []string{"accountlocked", "disputereminder", "accountterminated", "accountrestored"}
func TestDisputeTemplatesRender(t *testing.T) {
for _, name := range disputeTemplates {
t.Run(name, func(t *testing.T) {
m, err := render(name, sampleNotice())
if err != nil {
t.Fatalf("render: %v", err)
}
if !strings.Contains(m.Subject, "Smith & Sons") {
t.Errorf("subject %q does not name the account verbatim", m.Subject)
}
for label, body := range map[string]string{"text": m.Text, "html": m.HTML} {
if strings.Contains(body, "<no value>") {
t.Errorf("%s body has an unfilled field", label)
}
if strings.Contains(body, "—") {
t.Errorf("%s body contains an em dash", label)
}
}
})
}
}
func TestDisputeRouteIsStated(t *testing.T) {
for _, name := range []string{"accountlocked", "disputereminder"} {
m, err := render(name, sampleNotice())
if err != nil {
t.Fatalf("render %s: %v", name, err)
}
for _, want := range []string{"disputes@vantage.example", "dsp_123", "17 September 2026"} {
if !strings.Contains(m.Text, want) {
t.Errorf("%s text is missing %q", name, want)
}
}
}
}
func TestInstanceRows(t *testing.T) {
rows := sampleNotice().InstanceRows()
if len(rows) != 2 {
t.Fatalf("got %d rows, want 2", len(rows))
}
if rows[0]["v"] != "smith-prod" {
t.Errorf("cloud row = %v", rows[0])
}
if v, _ := rows[1]["v"].(string); !strings.Contains(v, "licence ends 2 November 2026") {
t.Errorf("self-hosted row = %v", rows[1])
}
}