feat: complete SOP version management

This commit is contained in:
Eric 1549169735@qq.com
2026-08-08 23:29:56 +08:00
parent 4b240499c2
commit e32025d2ca
40 changed files with 966 additions and 159 deletions

View File

@@ -0,0 +1,30 @@
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)
}
})
}
}