summaryrefslogtreecommitdiffstats
path: root/api4/brand_test.go
blob: c1568c5cc2cd7c58e1a7b115cd062586b3f7d110 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2017-present 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 th.TearDown()
	Client := th.Client

	_, resp := Client.GetBrandImage()
	CheckNotFoundStatus(t, resp)

	Client.Logout()
	_, resp = Client.GetBrandImage()
	CheckNotFoundStatus(t, resp)

	_, resp = th.SystemAdminClient.GetBrandImage()
	CheckNotFoundStatus(t, resp)
}

func TestUploadBrandImage(t *testing.T) {
	th := Setup().InitBasic().InitSystemAdmin()
	defer th.TearDown()
	Client := th.Client

	data, err := readTestFile("test.png")
	if err != nil {
		t.Fatal(err)
	}

	_, resp := Client.UploadBrandImage(data)
	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.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)
	CheckCreatedStatus(t, resp)
}