diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-10-02 08:04:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-02 08:04:38 +0200 |
commit | c82a84ed765bd9c4d601b93201d93af92f6ee742 (patch) | |
tree | 468b65659656bea32721cda7a193dcc83f93a678 /api4/user_test.go | |
parent | 3e462713debd5c992aa071bed902110bed88ec67 (diff) | |
download | chat-c82a84ed765bd9c4d601b93201d93af92f6ee742.tar.gz chat-c82a84ed765bd9c4d601b93201d93af92f6ee742.tar.bz2 chat-c82a84ed765bd9c4d601b93201d93af92f6ee742.zip |
MM-12067: Add SetDefaultProfileImage to reset the user profile image to a generated one (#9449)
* MM-12067: Add SetDefaultProfileImage to reset the user profile image to a generated one
* Allow to get the default profile image for my user
* Allowing to reset the last update image date to 0
* PR reviews
Diffstat (limited to 'api4/user_test.go')
-rw-r--r-- | api4/user_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/api4/user_test.go b/api4/user_test.go index a9aa967be..d50dfa3b6 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -2309,6 +2309,50 @@ func TestSetProfileImage(t *testing.T) { t.Fatal(err) } } + +func TestSetDefaultProfileImage(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() + Client := th.Client + user := th.BasicUser + + ok, resp := Client.SetDefaultProfileImage(user.Id) + if !ok { + t.Fatal(resp.Error) + } + CheckNoError(t, resp) + + ok, resp = Client.SetDefaultProfileImage(model.NewId()) + if ok { + t.Fatal("Should return false, set profile image not allowed") + } + CheckForbiddenStatus(t, resp) + + // status code returns either forbidden or unauthorized + // note: forbidden is set as default at Client4.SetDefaultProfileImage when request is terminated early by server + Client.Logout() + _, resp = Client.SetDefaultProfileImage(user.Id) + if resp.StatusCode == http.StatusForbidden { + CheckForbiddenStatus(t, resp) + } else if resp.StatusCode == http.StatusUnauthorized { + CheckUnauthorizedStatus(t, resp) + } else { + t.Fatal("Should have failed either forbidden or unauthorized") + } + + _, resp = th.SystemAdminClient.SetDefaultProfileImage(user.Id) + CheckNoError(t, resp) + + ruser, err := th.App.GetUser(user.Id) + require.Nil(t, err) + assert.Equal(t, int64(0), ruser.LastPictureUpdate, "Picture should have resetted to default") + + info := &model.FileInfo{Path: "users/" + user.Id + "/profile.png"} + if err := th.cleanupTestFile(info); err != nil { + t.Fatal(err) + } +} + func TestCBALogin(t *testing.T) { th := Setup().InitBasic() defer th.TearDown() |