refactor: Trim spaces from name and color in custom profile attribute select option constructor

This commit is contained in:
Julien Tant (aider)
2025-02-12 12:41:14 -07:00
parent b924431499
commit 328c898a3f
2 changed files with 13 additions and 3 deletions
@@ -3,7 +3,10 @@
package model
import "errors"
import (
"errors"
"strings"
)
const CustomProfileAttributesPropertyGroupName = "custom_profile_attributes"
@@ -35,8 +38,8 @@ type CustomProfileAttributesSelectOption struct {
func NewCustomProfileAttributeSelectOption(name, color string) CustomProfileAttributesSelectOption {
return CustomProfileAttributesSelectOption{
ID: NewId(),
Name: name,
Color: color,
Name: strings.TrimSpace(name),
Color: strings.TrimSpace(color),
}
}
@@ -18,6 +18,13 @@ func TestNewCustomProfileAttributeSelectOption(t *testing.T) {
assert.Equal(t, "Test Option", option.Name)
assert.Equal(t, "#FF0000", option.Color)
})
t.Run("trims spaces from name and color", func(t *testing.T) {
option := NewCustomProfileAttributeSelectOption(" Test Option ", " #FF0000 ")
assert.Equal(t, "Test Option", option.Name)
assert.Equal(t, "#FF0000", option.Color)
})
}
func TestCustomProfileAttributeSelectOptionIsValid(t *testing.T) {