2022-09-28 09:01:17 +02:00
|
|
|
package form
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-06-28 16:07:06 +02:00
|
|
|
"github.com/photoprism/photoprism/pkg/authn"
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUser(t *testing.T) {
|
|
|
|
form := &User{UserName: "foobar", UserEmail: "test@test.com", Password: "passwd"}
|
|
|
|
|
|
|
|
assert.Equal(t, "foobar", form.UserName)
|
|
|
|
assert.Equal(t, "test@test.com", form.UserEmail)
|
|
|
|
assert.Equal(t, "passwd", form.Password)
|
|
|
|
}
|
|
|
|
|
2023-03-08 23:30:39 +01:00
|
|
|
func TestUser_Username(t *testing.T) {
|
2022-09-28 09:01:17 +02:00
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd"}
|
2023-03-08 23:30:39 +01:00
|
|
|
assert.Equal(t, "", form.Username())
|
2022-09-28 09:01:17 +02:00
|
|
|
})
|
|
|
|
t.Run("Valid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "foobar", UserEmail: "test@test.com", Password: "passwd"}
|
2023-03-08 23:30:39 +01:00
|
|
|
assert.Equal(t, "foobar", form.Username())
|
2022-09-28 09:01:17 +02:00
|
|
|
})
|
|
|
|
t.Run("Invalid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: " Foo Bar4w45 !", UserEmail: "test@test.com", Password: "passwd"}
|
2023-03-08 23:30:39 +01:00
|
|
|
assert.Equal(t, "foo bar4w45 !", form.Username())
|
2022-09-28 09:01:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-06-28 16:07:06 +02:00
|
|
|
func TestUser_Provider(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", AuthProvider: ""}
|
|
|
|
assert.Equal(t, authn.ProviderDefault, form.Provider())
|
|
|
|
})
|
|
|
|
t.Run("Valid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", AuthProvider: "local"}
|
|
|
|
assert.Equal(t, authn.ProviderLocal, form.Provider())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-28 09:01:17 +02:00
|
|
|
func TestUser_Email(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "foobar", UserEmail: "", Password: "passwd"}
|
|
|
|
assert.Equal(t, "", form.Email())
|
|
|
|
})
|
|
|
|
t.Run("Valid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "foobar", UserEmail: "test@test.com", Password: "passwd"}
|
|
|
|
assert.Equal(t, "test@test.com", form.Email())
|
|
|
|
})
|
|
|
|
t.Run("Invalid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: " Foo Bar4w45 !", UserEmail: " testtest.srg awrygcom ", Password: "passwd"}
|
|
|
|
assert.Equal(t, "", form.Email())
|
|
|
|
})
|
|
|
|
}
|
2023-06-28 16:07:06 +02:00
|
|
|
|
|
|
|
func TestUser_Role(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", UserRole: ""}
|
|
|
|
assert.Equal(t, "", form.Role())
|
|
|
|
})
|
|
|
|
t.Run("Valid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", UserRole: "admin"}
|
|
|
|
assert.Equal(t, "admin", form.Role())
|
|
|
|
})
|
|
|
|
t.Run("Invalid", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "John", UserEmail: "test@test.com", Password: "passwd", UserRole: "ad&*min"}
|
|
|
|
assert.Equal(t, "admin", form.Role())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUser_Attr(t *testing.T) {
|
|
|
|
t.Run("Empty", func(t *testing.T) {
|
|
|
|
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd", UserAttr: ""}
|
|
|
|
assert.Equal(t, "", form.Attr())
|
|
|
|
})
|
|
|
|
}
|