package mail_test import ( "context" "testing" "git.lohmar.co.uk/cclohmar/NextMyDay/internal/core/mail" ) // TestFakeRecordsAndFilters: the test seam records every message and can filter // by recipient (case-insensitive). func TestFakeRecordsAndFilters(t *testing.T) { f := mail.NewFake() ctx := context.Background() if err := f.Send(ctx, mail.Message{To: "a@example.com", Subject: "one", Body: "hi"}); err != nil { t.Fatalf("Send: %v", err) } if err := f.Send(ctx, mail.Message{To: "B@Example.com", Subject: "two"}); err != nil { t.Fatalf("Send: %v", err) } if got := len(f.Sent()); got != 2 { t.Fatalf("Sent len = %d, want 2", got) } toB := f.To("b@example.com") if len(toB) != 1 || toB[0].Subject != "two" { t.Errorf("To(b@example.com) = %+v, want the second message", toB) } if len(f.To("nobody@example.com")) != 0 { t.Error("To returned a message for an unknown recipient") } } // TestNopSend: the unconfigured fallback discards silently. func TestNopSend(t *testing.T) { if err := (mail.Nop{}).Send(context.Background(), mail.Message{To: "x@example.com"}); err != nil { t.Errorf("Nop.Send = %v, want nil", err) } } // TestSMTPRequiresHost: the SMTP mailer fails closed without a host. func TestSMTPRequiresHost(t *testing.T) { m := mail.NewSMTP("", 25, "", "", "myday@example.com") if err := m.Send(context.Background(), mail.Message{To: "x@example.com"}); err == nil { t.Error("SMTP.Send with no host = nil, want an error") } }