test(07-01): add failing tests for passwords, locale, and validation

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-09-22 13:36:08 +02:00
parent cad445a235
commit bccd7f8f35
3 changed files with 154 additions and 0 deletions

View File

@@ -135,6 +135,61 @@ func TestValidateBooleanNoop(t *testing.T) {
}
}
func TestValidateEmailConfirmedDifferentMimes(t *testing.T) {
errs, err := Validate(t.Context(), nil, nil, map[string]string{"email": "email"}, map[string]any{"email": "not-an-email"}, nil)
if err != nil {
t.Fatal(err)
}
if len(errs["email"]) == 0 {
t.Fatal("not-an-email must fail")
}
errs, err = Validate(t.Context(), nil, nil, map[string]string{"email": "email"}, map[string]any{"email": "a@b.com"}, nil)
if err != nil {
t.Fatal(err)
}
if len(errs) != 0 {
t.Fatalf("a@b.com = %v", errs)
}
rules := map[string]string{"password": "confirmed"}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{
"password": "secret", "password_confirmation": "secret",
}, nil)
if err != nil || len(errs) != 0 {
t.Fatalf("confirmed match: %v %v", errs, err)
}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{
"password": "secret", "password_confirmation": "other",
}, nil)
if err != nil || len(errs["password"]) == 0 {
t.Fatalf("confirmed mismatch: %v %v", errs, err)
}
rules = map[string]string{"password": "different:current_password"}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{
"password": "same", "current_password": "same",
}, nil)
if err != nil || len(errs["password"]) == 0 {
t.Fatalf("different equal: %v %v", errs, err)
}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{
"password": "new", "current_password": "old",
}, nil)
if err != nil || len(errs) != 0 {
t.Fatalf("different distinct: %v %v", errs, err)
}
rules = map[string]string{"avatar": "mimes:jpeg,jpg,png,webp,gif"}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{"avatar": "PNG"}, nil)
if err != nil || len(errs) != 0 {
t.Fatalf("png: %v %v", errs, err)
}
errs, err = Validate(t.Context(), nil, nil, rules, map[string]any{"avatar": "svg"}, nil)
if err != nil || len(errs["avatar"]) == 0 {
t.Fatalf("svg: %v %v", errs, err)
}
}
func TestValidateUnrecognizedRule(t *testing.T) {
_, err := Validate(t.Context(), nil, nil, map[string]string{"name": "required|nope"}, map[string]any{"name": "x"}, nil)
if err == nil || !strings.Contains(err.Error(), "nope") {