summaryrefslogtreecommitdiffstats
path: root/api4/brand_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-14 09:35:48 -0400
committerGitHub <noreply@github.com>2017-03-14 09:35:48 -0400
commitad0ed008fe54534fcc089f479df606ab921901a9 (patch)
treea5fda084fb7ea61941449b393a6084f0c049195c /api4/brand_test.go
parentd03367c56005470396d883d273323ecbd8d4f243 (diff)
downloadchat-ad0ed008fe54534fcc089f479df606ab921901a9.tar.gz
chat-ad0ed008fe54534fcc089f479df606ab921901a9.tar.bz2
chat-ad0ed008fe54534fcc089f479df606ab921901a9.zip
Implement brand image endpoints for APIv4 (#5733)
* Implement brand image endpoints for APIv4 * Fix unit test
Diffstat (limited to 'api4/brand_test.go')
-rw-r--r--api4/brand_test.go69
1 files changed, 69 insertions, 0 deletions
diff --git a/api4/brand_test.go b/api4/brand_test.go
new file mode 100644
index 000000000..fd5e472a8
--- /dev/null
+++ b/api4/brand_test.go
@@ -0,0 +1,69 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "net/http"
+ "testing"
+)
+
+func TestGetBrandImage(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ data, resp := Client.GetBrandImage()
+ CheckNoError(t, resp)
+
+ if len(data) != 0 {
+ t.Fatal("no image uploaded - should be empty")
+ }
+
+ Client.Logout()
+ data, resp = Client.GetBrandImage()
+ CheckNoError(t, resp)
+
+ if len(data) != 0 {
+ t.Fatal("no image uploaded - should be empty")
+ }
+
+ data, resp = th.SystemAdminClient.GetBrandImage()
+ CheckNoError(t, resp)
+
+ if len(data) != 0 {
+ t.Fatal("no image uploaded - should be empty")
+ }
+}
+
+func TestUploadBrandImage(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+
+ data, err := readTestFile("test.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ ok, resp := Client.UploadBrandImage(data)
+ CheckForbiddenStatus(t, resp)
+ if ok {
+ t.Fatal("Should return false, set brand image not allowed")
+ }
+
+ // 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.UploadBrandImage(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.UploadBrandImage(data)
+ CheckNotImplementedStatus(t, resp)
+}