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
|
// 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, "store.sql_team.save.domain_exists.app_error")
CheckBadRequestStatus(t, resp)
rteam.Name = ""
_, resp = Client.CreateTeam(rteam)
CheckErrorMessage(t, resp, "model.team.is_valid.characters.app_error")
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.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.TeamSettings.EnableTeamCreation = false
utils.SetDefaultRolesBasedOnConfig()
th.LoginBasic()
_, resp = Client.CreateTeam(team)
CheckForbiddenStatus(t, resp)
}
|