mirror of
https://github.com/mattermost/mattermost.git
synced 2026-09-24 16:05:00 +08:00
refactor: Cleanup whitespace and remove empty Attrs in custom profile attributes test
This commit is contained in:
committed by
Julien Tant (aider)
parent
dbdb47d758
commit
7ab4455f9f
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user