Files
aura-crm/production/backend/internal/customfields/handler_test.go
T

40 lines
1.2 KiB
Go

package customfields
import "testing"
func TestCreateInputValidateCatalogLink(t *testing.T) {
cases := []struct {
name string
input createInput
want string
}{
{
"select with catalog_type_id needs no options",
createInput{Label: "Способ оплаты", FieldType: "select", CatalogTypeID: "abc"},
"",
},
{
"select without catalog_type_id still needs options",
createInput{Label: "Способ оплаты", FieldType: "select", CatalogTypeID: ""},
"select field requires at least one option, or a catalog_type_id",
},
{
"catalog_type_id on a non-select field is rejected",
createInput{Label: "Комментарий", FieldType: "text", CatalogTypeID: "abc"},
"catalog_type_id is only valid for select fields",
},
{
"select with both catalog_type_id and static options is fine (options just get ignored at write time)",
createInput{Label: "Способ оплаты", FieldType: "select", CatalogTypeID: "abc", Options: []string{"x"}},
"",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := tc.input.validate(); got != tc.want {
t.Errorf("validate() = %q, want %q", got, tc.want)
}
})
}
}