37 lines
1.3 KiB
Go
37 lines
1.3 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
// Confirms docs/MAIL_SETUP.md is telling the truth about the committed `.env`:
|
|
// a sender is set, a host is not, and the server therefore reports mail OFF with
|
|
// a reason naming the variable — rather than trying and failing to send.
|
|
func TestCommittedEnvLeavesMailOffWithAReason(t *testing.T) {
|
|
t.Setenv("MAIL_HOST", "")
|
|
t.Setenv("MAIL_PORT", "587")
|
|
t.Setenv("MAIL_FROM", "care@nearledaily.com")
|
|
t.Setenv("MAIL_FROM_NAME", "Nearle")
|
|
t.Setenv("MAIL_CONSOLE_URL", "https://app.nearledaily.com")
|
|
|
|
cfg := MailFromEnv()
|
|
if cfg.Enabled() {
|
|
t.Fatal("mail reported as enabled with no host")
|
|
}
|
|
if cfg.Why() == "" || cfg.Why()[:9] != "MAIL_HOST" {
|
|
t.Fatalf("the reason does not name the missing variable: %q", cfg.Why())
|
|
}
|
|
|
|
// And with the Postal host supplied from .env.secrets, it comes on and the
|
|
// link points at the MERCHANT console.
|
|
t.Setenv("MAIL_HOST", "postal.nearledaily.com")
|
|
on := MailFromEnv()
|
|
if !on.Enabled() {
|
|
t.Fatalf("still off with a host set: %s", on.Why())
|
|
}
|
|
if got := on.InviteLink("i1.abc.def"); got != "https://app.nearledaily.com/set-password?t=i1.abc.def" {
|
|
t.Fatalf("the invitation would point at %q", got)
|
|
}
|
|
if on.Address() != "postal.nearledaily.com:587" {
|
|
t.Fatalf("wrong SMTP address: %q", on.Address())
|
|
}
|
|
}
|