mirror of
https://github.com/miniflux/v2.git
synced 2025-08-21 18:11:09 +00:00
Add integration tests for users
This commit is contained in:
parent
142e8b3e0c
commit
ec0f642d5d
11 changed files with 267 additions and 33 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
package model
|
||||
|
||||
import "github.com/miniflux/miniflux2/errors"
|
||||
|
||||
// GetThemes returns the list of available themes.
|
||||
func GetThemes() map[string]string {
|
||||
return map[string]string{
|
||||
|
@ -11,3 +13,14 @@ func GetThemes() map[string]string {
|
|||
"black": "Black",
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateTheme validates theme value.
|
||||
func ValidateTheme(theme string) error {
|
||||
for key := range GetThemes() {
|
||||
if key == theme {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return errors.NewLocalizedError("Invalid theme.")
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ func NewUser() *User {
|
|||
return &User{Extra: make(map[string]string)}
|
||||
}
|
||||
|
||||
// ValidateUserCreation validates new user.
|
||||
func (u User) ValidateUserCreation() error {
|
||||
if err := u.ValidateUserLogin(); err != nil {
|
||||
return err
|
||||
|
@ -39,6 +40,7 @@ func (u User) ValidateUserCreation() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ValidateUserModification validates user for modification.
|
||||
func (u User) ValidateUserModification() error {
|
||||
if u.Username == "" {
|
||||
return errors.New("The username is mandatory")
|
||||
|
@ -48,9 +50,14 @@ func (u User) ValidateUserModification() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := ValidateTheme(u.Theme); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ValidateUserLogin validates user credential requirements.
|
||||
func (u User) ValidateUserLogin() error {
|
||||
if u.Username == "" {
|
||||
return errors.New("The username is mandatory")
|
||||
|
@ -63,6 +70,7 @@ func (u User) ValidateUserLogin() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ValidatePassword validates user password requirements.
|
||||
func (u User) ValidatePassword() error {
|
||||
if u.Password != "" && len(u.Password) < 6 {
|
||||
return errors.New("The password must have at least 6 characters")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue