package scenario import ( "encoding/json" "testing" ) func TestValidateFieldInput(t *testing.T) { tests := []struct { name string input fieldInput wantErr bool }{ {name: "text without options", input: fieldInput{FieldKey: "customer_name", FieldType: "text"}}, {name: "select options", input: fieldInput{FieldKey: "pet_type", FieldType: "select", Options: json.RawMessage(`["猫","狗"]`)}}, {name: "select missing options", input: fieldInput{FieldKey: "pet_type", FieldType: "select"}, wantErr: true}, {name: "invalid key", input: fieldInput{FieldKey: "1pet", FieldType: "text"}, wantErr: true}, {name: "options object", input: fieldInput{FieldKey: "pet_type", FieldType: "select", Options: json.RawMessage(`{"猫":1}`)}, wantErr: true}, {name: "options null", input: fieldInput{FieldKey: "pet_note", FieldType: "text", Options: json.RawMessage(`null`)}, wantErr: true}, {name: "validation array", input: fieldInput{FieldKey: "pet_age", FieldType: "number", Validation: json.RawMessage(`[1]`)}, wantErr: true}, {name: "validation null", input: fieldInput{FieldKey: "pet_age", FieldType: "number", Validation: json.RawMessage(`null`)}, wantErr: true}, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { if err := validateFieldInput(test.input); (err != nil) != test.wantErr { t.Fatalf("validateFieldInput() error = %v, wantErr %v", err, test.wantErr) } }) } }