English-only messages, rate limiting, min fill time, and normalized email validation; improve modal video serving with posters, correct MIME types, and no gzip on gallery media. Co-authored-by: Cursor <cursoragent@cursor.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package contact
|
|
|
|
import "testing"
|
|
|
|
func TestParse_valid(t *testing.T) {
|
|
sub, errs := Parse("Jimmy", "jim@example.com", "Hello there, this is a test message.")
|
|
if errs.Any() {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if sub.Name != "Jimmy" || sub.Email != "jim@example.com" {
|
|
t.Fatalf("got %+v", sub)
|
|
}
|
|
}
|
|
|
|
func TestParse_normalizesEmail(t *testing.T) {
|
|
sub, errs := Parse("Jimmy", "Jane Doe <jane@example.com>", "Hello there, this is a test message.")
|
|
if errs.Any() {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if sub.Email != "jane@example.com" {
|
|
t.Fatalf("email = %q", sub.Email)
|
|
}
|
|
}
|
|
|
|
func TestParse_shortMessage(t *testing.T) {
|
|
_, errs := Parse("Jimmy", "jim@example.com", "short")
|
|
if errs["message"] == "" {
|
|
t.Fatal("expected message error")
|
|
}
|
|
}
|
|
|
|
func TestParse_invalidEmail(t *testing.T) {
|
|
_, errs := Parse("Jimmy", "not-an-email", "This message is long enough to pass validation here.")
|
|
if errs["email"] == "" {
|
|
t.Fatal("expected email error")
|
|
}
|
|
}
|
|
|
|
func TestParse_notEnglish(t *testing.T) {
|
|
_, errs := Parse("Jimmy", "jim@example.com", "これは日本語のテストメッセージです。十分な長さがあります。")
|
|
if errs["message"] == "" {
|
|
t.Fatal("expected English-only message error")
|
|
}
|
|
}
|