feat(05-05): accept boolean validation token

- Treat Laravel boolean as a type-check no-op in lagoon.Validate
- Settings.search_use_typesense uses this rule string
This commit is contained in:
Jakub Zych
2026-09-18 20:14:46 +02:00
parent 678b216900
commit 4df7e016a2
2 changed files with 15 additions and 0 deletions

View File

@@ -85,6 +85,8 @@ func validateField(ctx context.Context, tx *gorm.DB, model any, field, rule stri
tags = append(tags, oneofTag(strings.Split(arg, ",")))
case "unique":
uniqueTable = arg
case "boolean":
// Go's bool field type already enforces this; treat as a type-check no-op.
default:
return nil, fmt.Errorf("lagoon: unrecognized validation rule %q", tok)
}

View File

@@ -73,6 +73,19 @@ func TestValidateMoneyRange(t *testing.T) {
}
}
func TestValidateBooleanNoop(t *testing.T) {
rules := map[string]string{"search_use_typesense": "boolean"}
for _, v := range []any{true, false} {
errs, err := Validate(t.Context(), nil, nil, rules, map[string]any{"search_use_typesense": v}, nil)
if err != nil {
t.Fatal(err)
}
if len(errs) != 0 {
t.Fatalf("boolean %v = %v", v, errs)
}
}
}
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") {