summaryrefslogtreecommitdiffstats
path: root/api4/team_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-01-31 07:59:36 -0500
committerGitHub <noreply@github.com>2017-01-31 07:59:36 -0500
commit7431050b427af88c5e5358bf086176d7a680149b (patch)
treed75e8bd406086509e032be9b65cb42681393cd92 /api4/team_test.go
parent450c0b3ccb091a3f84f35aca0319ba358ffd5633 (diff)
downloadchat-7431050b427af88c5e5358bf086176d7a680149b.tar.gz
chat-7431050b427af88c5e5358bf086176d7a680149b.tar.bz2
chat-7431050b427af88c5e5358bf086176d7a680149b.zip
Implement POST /teams endpoint (#5220)
Diffstat (limited to 'api4/team_test.go')
-rw-r--r--api4/team_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/api4/team_test.go b/api4/team_test.go
new file mode 100644
index 000000000..6e4f0c427
--- /dev/null
+++ b/api4/team_test.go
@@ -0,0 +1,75 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "net/http"
+ "strconv"
+ "testing"
+
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
+)
+
+func TestCreateTeam(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.Client
+
+ team := &model.Team{Name: GenerateTestUsername(), DisplayName: "Some Team", Type: model.TEAM_OPEN}
+ rteam, resp := Client.CreateTeam(team)
+ CheckNoError(t, resp)
+
+ if rteam.Name != team.Name {
+ t.Fatal("names did not match")
+ }
+
+ if rteam.DisplayName != team.DisplayName {
+ t.Fatal("display names did not match")
+ }
+
+ if rteam.Type != team.Type {
+ t.Fatal("types did not match")
+ }
+
+ _, resp = Client.CreateTeam(rteam)
+ CheckBadRequestStatus(t, resp)
+
+ rteam.Id = ""
+ _, resp = Client.CreateTeam(rteam)
+ CheckErrorMessage(t, resp, "A team with that name already exists")
+ CheckBadRequestStatus(t, resp)
+
+ rteam.Name = ""
+ _, resp = Client.CreateTeam(rteam)
+ CheckErrorMessage(t, resp, "Name must be 2 or more lowercase alphanumeric characters")
+ CheckBadRequestStatus(t, resp)
+
+ if r, err := Client.DoApiPost("/teams", "garbage"); err == nil {
+ t.Fatal("should have errored")
+ } else {
+ if r.StatusCode != http.StatusBadRequest {
+ t.Log("actual: " + strconv.Itoa(r.StatusCode))
+ t.Log("expected: " + strconv.Itoa(http.StatusBadRequest))
+ t.Fatal("wrong status code")
+ }
+ }
+
+ Client.Logout()
+
+ _, resp = Client.CreateTeam(rteam)
+ CheckUnauthorizedStatus(t, resp)
+
+ // Update permission
+ enableTeamCreation := utils.Cfg.TeamSettings.EnableTeamCreation
+ defer func() {
+ utils.Cfg.TeamSettings.EnableTeamCreation = enableTeamCreation
+ }()
+ utils.Cfg.TeamSettings.EnableTeamCreation = false
+ utils.SetDefaultRolesBasedOnConfig()
+
+ th.LoginBasic()
+ _, resp = Client.CreateTeam(team)
+ CheckForbiddenStatus(t, resp)
+
+}