[MM-34725] app/user: check if username or email is in use before patching a user (#17392)
* app/user: check if username or email is in use before patching a user * reflect review comments * fix tests
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3ea75332e7
Коммит
3a13987ee1
@@ -471,7 +471,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
user.Email = newEmail
|
||||
user3, err := th.App.UpdateUser(user, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, err.Id, "store.sql_user.update.email_taken.app_error")
|
||||
assert.Equal(t, err.Id, "app.user.save.email_exists.app_error")
|
||||
assert.Nil(t, user3)
|
||||
})
|
||||
|
||||
@@ -514,7 +514,7 @@ func TestUpdateUserEmail(t *testing.T) {
|
||||
user.Email = newEmail
|
||||
user3, err := th.App.UpdateUser(user, false)
|
||||
require.NotNil(t, err)
|
||||
assert.Equal(t, err.Id, "store.sql_user.update.email_taken.app_error")
|
||||
assert.Equal(t, err.Id, "app.user.save.email_exists.app_error")
|
||||
assert.Nil(t, user3)
|
||||
})
|
||||
}
|
||||
@@ -1457,3 +1457,37 @@ func TestDeactivateMfa(t *testing.T) {
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPatchUser(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
testUser := th.CreateUser()
|
||||
defer th.App.PermanentDeleteUser(testUser)
|
||||
|
||||
t.Run("Patch with a username already exists", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
Username: model.NewString(th.BasicUser.Username),
|
||||
}, true)
|
||||
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "app.user.save.username_exists.app_error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("Patch with a email already exists", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
Email: model.NewString(th.BasicUser.Email),
|
||||
}, true)
|
||||
|
||||
require.NotNil(t, err)
|
||||
require.Equal(t, "app.user.save.email_exists.app_error", err.Id)
|
||||
})
|
||||
|
||||
t.Run("Patch username with a new username", func(t *testing.T) {
|
||||
_, err := th.App.PatchUser(testUser.Id, &model.UserPatch{
|
||||
Username: model.NewString(model.NewId()),
|
||||
}, true)
|
||||
|
||||
require.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user