MM-30041: Return correct error message for user save (#16117)

* MM-30041: Return correct error message for user save

We were collapsing all types of user conflict into a single
error message. Fixed it by inspecting the field of the invalidError type
and returning the correct message.

https://mattermost.atlassian.net/browse/MM-30041

```release-note
NONE
```

* Fix test errors

* Fix wrong message in test when comparing error messages

Co-authored-by: Rodrigo Villablanca <villa061004@gmail.com>
This commit is contained in:
Agniva De Sarker
2020-10-30 11:14:06 +05:30
committed by GitHub
co-authored by Rodrigo Villablanca
parent 1aadd36644
commit 325bff1176
7 changed files with 82 additions and 7 deletions
+1 -1
View File
@@ -881,7 +881,7 @@ func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
t.Helper()
require.NotNilf(t, resp.Error, "should have errored with message: %s", errorId)
require.Equalf(t, resp.Error.Id, errorId, "incorrect error message, actual: %s, expected: %s", resp.Error.Id, errorId)
require.Equalf(t, errorId, resp.Error.Id, "incorrect error message, actual: %s, expected: %s", resp.Error.Id, errorId)
}
func CheckStartsWith(t *testing.T, value, prefix, message string) {
+2 -2
View File
@@ -53,13 +53,13 @@ func TestCreateUser(t *testing.T) {
ruser.Username = GenerateTestUsername()
ruser.Password = "passwd1"
_, resp = th.Client.CreateUser(ruser)
CheckErrorMessage(t, resp, "app.user.save.existing.app_error")
CheckErrorMessage(t, resp, "app.user.save.email_exists.app_error")
CheckBadRequestStatus(t, resp)
ruser.Email = th.GenerateTestEmail()
ruser.Username = user.Username
_, resp = th.Client.CreateUser(ruser)
CheckErrorMessage(t, resp, "app.user.save.existing.app_error")
CheckErrorMessage(t, resp, "app.user.save.username_exists.app_error")
CheckBadRequestStatus(t, resp)
ruser.Email = ""