photoprism/internal/form/user_test.go
Michael Mayer f94ff54cc1 Auth: Improve account management page and config options #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-19 05:09:09 +02:00

45 lines
1.4 KiB
Go

package form
import (
"testing"
"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)
}
func TestUser_Name(t *testing.T) {
t.Run("Empty", func(t *testing.T) {
form := &User{UserName: "", UserEmail: "test@test.com", Password: "passwd"}
assert.Equal(t, "", form.Name())
})
t.Run("Valid", func(t *testing.T) {
form := &User{UserName: "foobar", UserEmail: "test@test.com", Password: "passwd"}
assert.Equal(t, "foobar", form.Name())
})
t.Run("Invalid", func(t *testing.T) {
form := &User{UserName: " Foo Bar4w45 !", UserEmail: "test@test.com", Password: "passwd"}
assert.Equal(t, "foobar4w45", form.Name())
})
}
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())
})
}