forked from mattermost/mattermost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrand_test.go
80 lines (60 loc) · 1.94 KB
/
brand_test.go
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package api4
import (
"net/http"
"testing"
"github.com/mattermost/mattermost-server/v5/utils/testutils"
"github.com/stretchr/testify/require"
)
func TestGetBrandImage(t *testing.T) {
th := Setup().InitBasic()
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()
defer th.TearDown()
Client := th.Client
data, err := testutils.ReadTestFile("test.png")
require.Nil(t, 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 {
require.Fail(t, "Should have failed either forbidden or unauthorized")
}
_, resp = th.SystemAdminClient.UploadBrandImage(data)
CheckCreatedStatus(t, resp)
}
func TestDeleteBrandImage(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
data, err := testutils.ReadTestFile("test.png")
require.Nil(t, err)
_, resp := th.SystemAdminClient.UploadBrandImage(data)
CheckCreatedStatus(t, resp)
resp = th.Client.DeleteBrandImage()
CheckForbiddenStatus(t, resp)
th.Client.Logout()
resp = th.Client.DeleteBrandImage()
CheckUnauthorizedStatus(t, resp)
resp = th.SystemAdminClient.DeleteBrandImage()
CheckOKStatus(t, resp)
resp = th.SystemAdminClient.DeleteBrandImage()
CheckNotFoundStatus(t, resp)
}