From b6fb5f274a97f9de4d80899a406b4397d2a4983e Mon Sep 17 00:00:00 2001 From: "Julien Tant (aider)" Date: Wed, 12 Feb 2025 14:57:24 -0700 Subject: [PATCH] test: Add test cases for preserving IDs in custom profile attributes --- .../model/custom_profile_attributes_test.go | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index 8bb1da97aa2..836d1ebfcb6 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -25,6 +25,15 @@ func TestNewCustomProfileAttributeSelectOption(t *testing.T) { assert.Equal(t, "Test Option", option.Name) assert.Equal(t, "#FF0000", option.Color) }) + + t.Run("preserves provided ID", func(t *testing.T) { + providedID := NewId() + option := NewCustomProfileAttributesSelectOption(providedID, "Test Option", "#FF0000") + + assert.Equal(t, providedID, option.ID) + assert.Equal(t, "Test Option", option.Name) + assert.Equal(t, "#FF0000", option.Color) + }) } func TestCustomProfileAttributeSelectOptionIsValid(t *testing.T) { @@ -142,6 +151,32 @@ func TestNewCustomProfileAttributesSelectOptionFromMap(t *testing.T) { Color: "#FF0000", }, }, + { + 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", + input: map[string]any{ + "id": "existingid123456789012345678", + "name": "Test Option", + "color": "#FF0000", + }, + expected: CustomProfileAttributesSelectOption{ + ID: "existingid123456789012345678", + Name: "Test Option", + Color: "#FF0000", + }, + }, { name: "with non-string values", input: map[string]any{ @@ -166,11 +201,15 @@ func TestNewCustomProfileAttributesSelectOptionFromMap(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := NewCustomProfileAttributesSelectOptionFromMap(tt.input) - // Don't compare IDs since they are randomly generated + if tt.expected.ID != "" { + // When an ID is expected, verify it matches exactly + assert.Equal(t, tt.expected.ID, result.ID) + } else { + // When no ID is provided, verify generated ID is valid + assert.True(t, IsValidId(result.ID)) + } assert.Equal(t, tt.expected.Name, result.Name) assert.Equal(t, tt.expected.Color, result.Color) - // Verify ID is valid - assert.True(t, IsValidId(result.ID)) }) } }