mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-10-11 20:29:04 +02:00
fix: fallback to username if chars in name are not supported for avatars
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
|
||||
datatype "github.com/pocket-id/pocket-id/backend/internal/model/types"
|
||||
"github.com/pocket-id/pocket-id/backend/internal/utils"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
@@ -88,16 +87,6 @@ func (u User) FullName() string {
|
||||
return u.Username
|
||||
}
|
||||
|
||||
func (u User) Initials() string {
|
||||
first := utils.GetFirstCharacter(u.FirstName)
|
||||
last := utils.GetFirstCharacter(u.LastName)
|
||||
if first != "" || last != "" {
|
||||
return strings.ToUpper(first + last)
|
||||
}
|
||||
|
||||
return strings.ToUpper(utils.GetFirstCharacter(u.Username))
|
||||
}
|
||||
|
||||
func (u User) LastModified() time.Time {
|
||||
if u.UpdatedAt != nil {
|
||||
return u.UpdatedAt.ToTime()
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUserInitials(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
user User
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "first and last name",
|
||||
user: User{Username: "username", FirstName: "John", LastName: "Doe"},
|
||||
expected: "JD",
|
||||
},
|
||||
{
|
||||
name: "first name only",
|
||||
user: User{Username: "username", FirstName: "John"},
|
||||
expected: "J",
|
||||
},
|
||||
{
|
||||
name: "last name only",
|
||||
user: User{Username: "username", LastName: "Doe"},
|
||||
expected: "D",
|
||||
},
|
||||
{
|
||||
name: "ASCII username",
|
||||
user: User{Username: "username"},
|
||||
expected: "U",
|
||||
},
|
||||
{
|
||||
name: "single-character username",
|
||||
user: User{Username: "a"},
|
||||
expected: "A",
|
||||
},
|
||||
{
|
||||
name: "empty username",
|
||||
user: User{},
|
||||
expected: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.expected, tt.user.Initials())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user