summaryrefslogtreecommitdiffstats
path: root/api4/user_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-02-28 22:11:56 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-02-28 08:11:55 -0500
commit66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4 (patch)
tree5ccb3fc95f07d996cc0830431a64a341fee6eb3a /api4/user_test.go
parentda902ef8bacb0751c7bd681abdc58039812d6430 (diff)
downloadchat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.tar.gz
chat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.tar.bz2
chat-66c5f7a31c5d0f26d394b94747c17ee55e5d5ce4.zip
Implementation of APIv4: POST users/{user_id}/image (#5537)
* APIv4: POST users/{user_id}/image * removed 'return' and rebased to master
Diffstat (limited to 'api4/user_test.go')
-rw-r--r--api4/user_test.go50
1 files changed, 47 insertions, 3 deletions
diff --git a/api4/user_test.go b/api4/user_test.go
index 5cdab21f5..c83bc98a9 100644
--- a/api4/user_test.go
+++ b/api4/user_test.go
@@ -967,15 +967,15 @@ func TestVerify(t *testing.T) {
ruser, resp := Client.CreateUser(&user)
- hashId := ruser.Id+utils.Cfg.EmailSettings.InviteSalt
+ hashId := ruser.Id + utils.Cfg.EmailSettings.InviteSalt
_, resp = Client.VerifyUserEmail(ruser.Id, hashId)
CheckNoError(t, resp)
- hashId = ruser.Id+GenerateTestId()
+ hashId = ruser.Id + GenerateTestId()
_, resp = Client.VerifyUserEmail(ruser.Id, hashId)
CheckBadRequestStatus(t, resp)
- // Comment per request from Joram, he will investigate why it fail with a wrong status
+ // Comment per request from Joram, he will investigate why it fail with a wrong status
// hashId = ruser.Id+GenerateTestId()
// _, resp = Client.VerifyUserEmail("", hashId)
// CheckBadRequestStatus(t, resp)
@@ -983,3 +983,47 @@ func TestVerify(t *testing.T) {
_, resp = Client.VerifyUserEmail(ruser.Id, "")
CheckBadRequestStatus(t, resp)
}
+
+func TestSetProfileImage(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ user := th.BasicUser
+
+ data, err := readTestFile("test.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ok, resp := Client.SetProfileImage(user.Id, data)
+ if !ok {
+ t.Fatal(resp.Error)
+ }
+ CheckNoError(t, resp)
+
+ ok, resp = Client.SetProfileImage(model.NewId(), data)
+ 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.SetProfileImage when request is terminated early by server
+ Client.Logout()
+ _, resp = Client.SetProfileImage(user.Id, data)
+ 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.SetProfileImage(user.Id, data)
+ CheckNoError(t, resp)
+
+ info := &model.FileInfo{Path: "users/" + user.Id + "/profile.png"}
+ if err := cleanupTestFile(info); err != nil {
+ t.Fatal(err)
+ }
+}