[MM-9720] fix bugs when trying to change for a in use email and check the number of parameters (#8772)
Этот коммит содержится в:
коммит произвёл
Derrick Anderson
родитель
4ce37601a1
Коммит
527bf9d3d3
@@ -422,6 +422,10 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
defer a.Shutdown()
|
defer a.Shutdown()
|
||||||
|
|
||||||
|
if len(args) != 2 {
|
||||||
|
return errors.New("Expected two arguments. See help text for details.")
|
||||||
|
}
|
||||||
|
|
||||||
newEmail := args[1]
|
newEmail := args[1]
|
||||||
|
|
||||||
if !model.IsValidEmail(newEmail) {
|
if !model.IsValidEmail(newEmail) {
|
||||||
@@ -440,7 +444,7 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
|||||||
user.Email = newEmail
|
user.Email = newEmail
|
||||||
_, errUpdate := a.UpdateUser(user, true)
|
_, errUpdate := a.UpdateUser(user, true)
|
||||||
if errUpdate != nil {
|
if errUpdate != nil {
|
||||||
return errUpdate
|
return errors.New(errUpdate.Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -104,7 +104,19 @@ func TestChangeUserEmail(t *testing.T) {
|
|||||||
// should fail because using an invalid email
|
// should fail because using an invalid email
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
|
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "wrong$email.com"))
|
||||||
|
|
||||||
|
// should fail because missing one parameter
|
||||||
|
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username))
|
||||||
|
|
||||||
|
// should fail because missing both parameters
|
||||||
|
require.Error(t, cmd.RunCommand(t, "user", "email"))
|
||||||
|
|
||||||
|
// should fail because have more than 2 parameters
|
||||||
|
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, "new@email.com", "extra!"))
|
||||||
|
|
||||||
// should fail because user not found
|
// should fail because user not found
|
||||||
require.Error(t, cmd.RunCommand(t, "user", "email", "invalidUser", newEmail))
|
require.Error(t, cmd.RunCommand(t, "user", "email", "invalidUser", newEmail))
|
||||||
|
|
||||||
|
// should fail because email already in use
|
||||||
|
require.Error(t, cmd.RunCommand(t, "user", "email", th.BasicUser.Username, th.BasicUser2.Email))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user