From 7ab4455f9feb88826fcf6abb3b93a8a7bb53ed3e Mon Sep 17 00:00:00 2001 From: Julien Tant Date: Tue, 25 Feb 2025 10:50:28 -0700 Subject: [PATCH] refactor: Cleanup whitespace and remove empty Attrs in custom profile attributes test --- .../model/custom_profile_attributes_test.go | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/server/public/model/custom_profile_attributes_test.go b/server/public/model/custom_profile_attributes_test.go index 54f2a4e8556..286c9e1ee6b 100644 --- a/server/public/model/custom_profile_attributes_test.go +++ b/server/public/model/custom_profile_attributes_test.go @@ -12,18 +12,18 @@ import ( func TestNewCPAFieldFromPropertyField(t *testing.T) { tests := []struct { - name string + name string propertyField *PropertyField - wantAttrs CPAAttrs - wantErr bool + wantAttrs CPAAttrs + wantErr bool }{ { name: "valid property field with all attributes", propertyField: &PropertyField{ - ID: NewId(), - GroupID: CustomProfileAttributesPropertyGroupName, - Name: "Test Field", - Type: PropertyFieldTypeSelect, + ID: NewId(), + GroupID: CustomProfileAttributesPropertyGroupName, + Name: "Test Field", + Type: PropertyFieldTypeSelect, Attrs: StringInterface{ CustomProfileAttributesPropertyAttrsVisibility: CustomProfileAttributesVisibilityAlways, CustomProfileAttributesPropertyAttrsSortOrder: "1", @@ -56,10 +56,10 @@ func TestNewCPAFieldFromPropertyField(t *testing.T) { { name: "valid property field with minimal attributes", propertyField: &PropertyField{ - ID: NewId(), - GroupID: CustomProfileAttributesPropertyGroupName, - Name: "Test Field", - Type: PropertyFieldTypeText, + ID: NewId(), + GroupID: CustomProfileAttributesPropertyGroupName, + Name: "Test Field", + Type: PropertyFieldTypeText, Attrs: StringInterface{ CustomProfileAttributesPropertyAttrsVisibility: CustomProfileAttributesVisibilityWhenSet, CustomProfileAttributesPropertyAttrsSortOrder: "2", @@ -82,7 +82,6 @@ func TestNewCPAFieldFromPropertyField(t *testing.T) { GroupID: CustomProfileAttributesPropertyGroupName, Name: "Empty Field", Type: PropertyFieldTypeText, - Attrs: StringInterface{}, CreateAt: GetMillis(), UpdateAt: GetMillis(), }, @@ -99,31 +98,31 @@ func TestNewCPAFieldFromPropertyField(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { cpaField, err := NewCPAFieldFromPropertyField(tt.propertyField) - + if tt.wantErr { require.Error(t, err) return } - + require.NoError(t, err) require.NotNil(t, cpaField) - + // Check that the PropertyField was copied correctly assert.Equal(t, tt.propertyField.ID, cpaField.ID) assert.Equal(t, tt.propertyField.GroupID, cpaField.GroupID) assert.Equal(t, tt.propertyField.Name, cpaField.Name) assert.Equal(t, tt.propertyField.Type, cpaField.Type) - + // Check that the attributes were parsed correctly assert.Equal(t, tt.wantAttrs.Visibility, cpaField.Attrs.Visibility) assert.Equal(t, tt.wantAttrs.SortOrder, cpaField.Attrs.SortOrder) assert.Equal(t, tt.wantAttrs.ValueType, cpaField.Attrs.ValueType) - + // For options, we need to check length since IDs will be different if tt.wantAttrs.Options != nil { require.NotNil(t, cpaField.Attrs.Options) assert.Equal(t, len(tt.wantAttrs.Options), len(cpaField.Attrs.Options)) - + if len(tt.wantAttrs.Options) > 0 { assert.Equal(t, tt.wantAttrs.Options[0].Name, cpaField.Attrs.Options[0].Name) assert.Equal(t, tt.wantAttrs.Options[0].Color, cpaField.Attrs.Options[0].Color) @@ -187,20 +186,20 @@ func TestCPAFieldToPropertyField(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { pf := tt.cpaField.ToPropertyField() - + require.NotNil(t, pf) - + // Check that the PropertyField was copied correctly assert.Equal(t, tt.cpaField.ID, pf.ID) assert.Equal(t, tt.cpaField.GroupID, pf.GroupID) assert.Equal(t, tt.cpaField.Name, pf.Name) assert.Equal(t, tt.cpaField.Type, pf.Type) - + // Check that the attributes were converted correctly assert.Equal(t, tt.cpaField.Attrs.Visibility, pf.Attrs[CustomProfileAttributesPropertyAttrsVisibility]) assert.Equal(t, tt.cpaField.Attrs.SortOrder, pf.Attrs[CustomProfileAttributesPropertyAttrsSortOrder]) assert.Equal(t, tt.cpaField.Attrs.ValueType, pf.Attrs[CustomProfileAttributesPropertyAttrsValueType]) - + // Check options options, ok := pf.Attrs[PropertyFieldAttributeOptions] if tt.cpaField.Attrs.Options != nil {