mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:07:31 +00:00
fix: set displayname correctly in EnsureDisplayName (#5702)
fix: EnsureDisplayName
This commit is contained in:
@@ -91,7 +91,13 @@ func (u *Human) CheckDomainPolicy(policy *DomainPolicy) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *Human) EnsureDisplayName() {
|
func (u *Human) EnsureDisplayName() {
|
||||||
if u.Profile != nil && u.DisplayName == "" && u.FirstName != "" && u.LastName != "" {
|
if u.Profile == nil {
|
||||||
|
u.Profile = new(Profile)
|
||||||
|
}
|
||||||
|
if u.DisplayName != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if u.FirstName != "" && u.LastName != "" {
|
||||||
u.DisplayName = u.FirstName + " " + u.LastName
|
u.DisplayName = u.FirstName + " " + u.LastName
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
78
internal/domain/human_test.go
Normal file
78
internal/domain/human_test.go
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHuman_EnsureDisplayName(t *testing.T) {
|
||||||
|
type fields struct {
|
||||||
|
Username string
|
||||||
|
Profile *Profile
|
||||||
|
Email *Email
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
fields fields
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
"display name set",
|
||||||
|
fields{
|
||||||
|
Username: "username",
|
||||||
|
Profile: &Profile{
|
||||||
|
FirstName: "firstName",
|
||||||
|
LastName: "lastName",
|
||||||
|
DisplayName: "displayName",
|
||||||
|
},
|
||||||
|
Email: &Email{
|
||||||
|
EmailAddress: "email",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"displayName",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"first and lastname set",
|
||||||
|
fields{
|
||||||
|
Username: "username",
|
||||||
|
Profile: &Profile{
|
||||||
|
FirstName: "firstName",
|
||||||
|
LastName: "lastName",
|
||||||
|
},
|
||||||
|
Email: &Email{
|
||||||
|
EmailAddress: "email",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"firstName lastName",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"profile nil, email set",
|
||||||
|
fields{
|
||||||
|
Username: "username",
|
||||||
|
Email: &Email{
|
||||||
|
EmailAddress: "email",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"email",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"email nil, username set",
|
||||||
|
fields{
|
||||||
|
Username: "username",
|
||||||
|
},
|
||||||
|
"username",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
u := &Human{
|
||||||
|
Username: tt.fields.Username,
|
||||||
|
Profile: tt.fields.Profile,
|
||||||
|
Email: tt.fields.Email,
|
||||||
|
}
|
||||||
|
u.EnsureDisplayName()
|
||||||
|
assert.Equal(t, tt.want, u.DisplayName)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user