summaryrefslogtreecommitdiffstats
path: root/api4/team_test.go
diff options
context:
space:
mode:
authorChristian Hoff <hoff.christian@posteo.de>2018-03-01 20:11:44 +0100
committerJoram Wilander <jwawilander@gmail.com>2018-03-01 19:11:44 +0000
commit2b3b6051d265edf131d006b2eb14f55284faf1e5 (patch)
tree2bf50fd4c6ff09daf897f818aaef0c357b67ca79 /api4/team_test.go
parent51c7198d53a2fbc4c7d47b3eb308781b69bf4b51 (diff)
downloadchat-2b3b6051d265edf131d006b2eb14f55284faf1e5.tar.gz
chat-2b3b6051d265edf131d006b2eb14f55284faf1e5.tar.bz2
chat-2b3b6051d265edf131d006b2eb14f55284faf1e5.zip
PLT-7567: Integration of Team Icons (#8284)
* PLT-7567: Integration of Team Icons * PLT-7567: Read replica workaround, upgrade logic moved, more concrete i18n key * PLT-7567: Read replica workaround, corrections * PLT-7567: upgrade correction
Diffstat (limited to 'api4/team_test.go')
-rw-r--r--api4/team_test.go81
1 files changed, 81 insertions, 0 deletions
diff --git a/api4/team_test.go b/api4/team_test.go
index faa90e511..04a0e9ae4 100644
--- a/api4/team_test.go
+++ b/api4/team_test.go
@@ -15,6 +15,8 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/utils"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
func TestCreateTeam(t *testing.T) {
@@ -1915,3 +1917,82 @@ func TestGetTeamInviteInfo(t *testing.T) {
_, resp = Client.GetTeamInviteInfo("junk")
CheckNotFoundStatus(t, resp)
}
+
+func TestSetTeamIcon(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer th.TearDown()
+ Client := th.Client
+ team := th.BasicTeam
+
+ data, err := readTestFile("test.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ th.LoginTeamAdmin()
+
+ ok, resp := Client.SetTeamIcon(team.Id, data)
+ if !ok {
+ t.Fatal(resp.Error)
+ }
+ CheckNoError(t, resp)
+
+ ok, resp = Client.SetTeamIcon(model.NewId(), data)
+ if ok {
+ t.Fatal("Should return false, set team icon not allowed")
+ }
+ CheckForbiddenStatus(t, resp)
+
+ th.LoginBasic()
+
+ _, resp = Client.SetTeamIcon(team.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")
+ }
+
+ Client.Logout()
+
+ _, resp = Client.SetTeamIcon(team.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")
+ }
+
+ teamBefore, err := th.App.GetTeam(team.Id)
+ require.Nil(t, err)
+
+ _, resp = th.SystemAdminClient.SetTeamIcon(team.Id, data)
+ CheckNoError(t, resp)
+
+ teamAfter, err := th.App.GetTeam(team.Id)
+ require.Nil(t, err)
+ assert.True(t, teamBefore.LastTeamIconUpdate < teamAfter.LastTeamIconUpdate, "LastTeamIconUpdate should have been updated for team")
+
+ info := &model.FileInfo{Path: "teams/" + team.Id + "/teamIcon.png"}
+ if err := th.cleanupTestFile(info); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestGetTeamIcon(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer th.TearDown()
+ Client := th.Client
+ team := th.BasicTeam
+
+ // should always fail because no initial image and no auto creation
+ _, resp := Client.GetTeamIcon(team.Id, "")
+ CheckNotFoundStatus(t, resp)
+
+ Client.Logout()
+
+ _, resp = Client.GetTeamIcon(team.Id, "")
+ CheckUnauthorizedStatus(t, resp)
+}