miniflux/ui/form/settings_test.go
Frédéric Guillot e45cc2d2aa Refactor user validation
Validate each user field for creation/modification via API and web UI
2021-01-03 21:36:35 -08:00

63 lines
1.2 KiB
Go

package form // import "miniflux.app/ui/form"
import (
"testing"
)
func TestValid(t *testing.T) {
settings := &SettingsForm{
Username: "user",
Password: "hunter2",
Confirmation: "hunter2",
Theme: "default",
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
if err != nil {
t.Error(err)
}
}
func TestConfirmationEmpty(t *testing.T) {
settings := &SettingsForm{
Username: "user",
Password: "hunter2",
Confirmation: "",
Theme: "default",
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
if err != nil {
t.Error(err)
}
if settings.Password != "" {
t.Error("Password should have been cleared")
}
}
func TestConfirmationIncorrect(t *testing.T) {
settings := &SettingsForm{
Username: "user",
Password: "hunter2",
Confirmation: "unter2",
Theme: "default",
Language: "en_US",
Timezone: "UTC",
EntryDirection: "asc",
EntriesPerPage: 50,
}
err := settings.Validate()
if err == nil {
t.Error("Validate should return an error")
}
}