Require email at registration (editable on profile), add a Resend mailer with idempotent first-answer sends, and keep answer saves independent of delivery.
22 lines
548 B
Go
22 lines
548 B
Go
package store
|
|
|
|
import "testing"
|
|
|
|
func TestValidateEmail(t *testing.T) {
|
|
cases := []struct {
|
|
in, want, err string
|
|
}{
|
|
{"", "", "Email is required."},
|
|
{" Alice@Example.COM ", "alice@example.com", ""},
|
|
{"not-an-email", "", "Enter a valid email address."},
|
|
{"a@b", "", "Enter a valid email address."},
|
|
{"ok@example.com", "ok@example.com", ""},
|
|
}
|
|
for _, tc := range cases {
|
|
got, msg := ValidateEmail(tc.in)
|
|
if got != tc.want || msg != tc.err {
|
|
t.Fatalf("%q: got (%q, %q) want (%q, %q)", tc.in, got, msg, tc.want, tc.err)
|
|
}
|
|
}
|
|
}
|