refactor: Modify CustomProfileAttributesSelectOption to use lowercase JSON keys

This commit is contained in:
Julien Tant (aider)
2025-02-12 15:33:26 -07:00
parent 861e12c1fc
commit bcca3d87c4
2 changed files with 9 additions and 56 deletions
@@ -54,9 +54,9 @@ func IsKnownCustomProfilteAttributesVisibility(visibility string) bool {
}
type CustomProfileAttributesSelectOption struct {
ID string
Name string
Color string
ID string `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
}
func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfileAttributesSelectOption {
@@ -64,31 +64,19 @@ func NewCustomProfileAttributesSelectOptionFromMap(m map[string]any) CustomProfi
name := ""
color := ""
if v, ok := m["ID"]; ok {
if vStr, ok := v.(string); ok {
id = vStr
}
} else if v, ok := m["id"]; ok {
if v, ok := m["id"]; ok {
if vStr, ok := v.(string); ok {
id = vStr
}
}
if v, ok := m["Name"]; ok {
if vStr, ok := v.(string); ok {
name = vStr
}
} else if v, ok := m["name"]; ok {
if v, ok := m["name"]; ok {
if vStr, ok := v.(string); ok {
name = vStr
}
}
if v, ok := m["Color"]; ok {
if vStr, ok := v.(string); ok {
color = vStr
}
} else if v, ok := m["color"]; ok {
if v, ok := m["color"]; ok {
if vStr, ok := v.(string); ok {
color = vStr
}
@@ -117,18 +117,7 @@ func TestNewCustomProfileAttributesSelectOptionFromMap(t *testing.T) {
expected CustomProfileAttributesSelectOption
}{
{
name: "title case keys",
input: map[string]any{
"Name": "Test Option",
"Color": "#FF0000",
},
expected: CustomProfileAttributesSelectOption{
Name: "Test Option",
Color: "#FF0000",
},
},
{
name: "lower case keys",
name: "valid option",
input: map[string]any{
"name": "Test Option",
"color": "#FF0000",
@@ -138,17 +127,6 @@ func TestNewCustomProfileAttributesSelectOptionFromMap(t *testing.T) {
Color: "#FF0000",
},
},
{
name: "mixed case keys",
input: map[string]any{
"Name": "Test Option",
"color": "#FF0000",
},
expected: CustomProfileAttributesSelectOption{
Name: "Test Option",
Color: "#FF0000",
},
},
{
name: "with spaces to trim",
input: map[string]any{
@@ -161,23 +139,10 @@ func TestNewCustomProfileAttributesSelectOptionFromMap(t *testing.T) {
},
},
{
name: "with provided ID",
input: map[string]any{
"ID": "existingid123456789012345678",
"Name": "Test Option",
"Color": "#FF0000",
},
expected: CustomProfileAttributesSelectOption{
ID: "existingid123456789012345678",
Name: "Test Option",
Color: "#FF0000",
},
},
{
name: "with provided lowercase id",
name: "with provided id",
input: map[string]any{
"id": "existingid123456789012345678",
"name": "Test Option",
"name": "Test Option",
"color": "#FF0000",
},
expected: CustomProfileAttributesSelectOption{