2021-08-26 18:02:53 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2021-08-28 13:55:37 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
2021-08-26 18:02:53 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserMap_Get(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Alice", func(t *testing.T) {
|
2021-08-26 18:02:53 +02:00
|
|
|
r := UserFixtures.Get("alice")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, "alice", r.UserName)
|
|
|
|
assert.Equal(t, "alice", r.Name())
|
2021-08-26 18:02:53 +02:00
|
|
|
assert.IsType(t, User{}, r)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
t.Run("Invalid", func(t *testing.T) {
|
2021-08-26 18:02:53 +02:00
|
|
|
r := UserFixtures.Get("monstera")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, "", r.UserName)
|
|
|
|
assert.Equal(t, "", r.Name())
|
2021-08-26 18:02:53 +02:00
|
|
|
assert.IsType(t, User{}, r)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUserMap_Pointer(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Alice", func(t *testing.T) {
|
2021-08-26 18:02:53 +02:00
|
|
|
r := UserFixtures.Pointer("alice")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, "alice", r.Name())
|
|
|
|
assert.Equal(t, "alice", r.UserName)
|
|
|
|
assert.Equal(t, "alice@example.com", r.Email())
|
|
|
|
assert.Equal(t, "alice@example.com", r.UserEmail)
|
|
|
|
assert.Equal(t, acl.RoleAdmin, r.AclRole())
|
2021-08-26 18:02:53 +02:00
|
|
|
assert.IsType(t, &User{}, r)
|
|
|
|
})
|
2022-09-28 09:01:17 +02:00
|
|
|
|
|
|
|
t.Run("Invalid", func(t *testing.T) {
|
2021-08-26 18:02:53 +02:00
|
|
|
r := UserFixtures.Pointer("monstera")
|
2022-09-28 09:01:17 +02:00
|
|
|
assert.Equal(t, "", r.UserName)
|
|
|
|
assert.Equal(t, "", r.Email())
|
|
|
|
assert.Equal(t, acl.RoleUnauthorized, r.AclRole())
|
2021-08-26 18:02:53 +02:00
|
|
|
assert.IsType(t, &User{}, r)
|
|
|
|
})
|
|
|
|
}
|