MM-23722 add endpoint for modify team privacy (#14287)
* MM-23722 add Rest API for updating team privacy * unit tests for UpdateTeamPrivacy
Этот коммит содержится в:
@@ -459,6 +459,76 @@ func TestPatchTeamSanitization(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestUpdateTeamPrivacy(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
createTeam := func(teamType string, allowOpenInvite bool) *model.Team {
|
||||
team := &model.Team{
|
||||
DisplayName: teamType + " Team",
|
||||
Description: "Some description",
|
||||
CompanyName: "Some company name",
|
||||
AllowOpenInvite: allowOpenInvite,
|
||||
InviteId: model.NewId(),
|
||||
Name: "aa-" + model.NewRandomTeamName() + "zz",
|
||||
Email: "success+" + model.NewId() + "@simulator.amazonses.com",
|
||||
Type: teamType,
|
||||
}
|
||||
team, _ = Client.CreateTeam(team)
|
||||
return team
|
||||
}
|
||||
|
||||
teamPublic := createTeam(model.TEAM_OPEN, true)
|
||||
teamPrivate := createTeam(model.TEAM_INVITE, false)
|
||||
|
||||
teamPublic2 := createTeam(model.TEAM_OPEN, true)
|
||||
teamPrivate2 := createTeam(model.TEAM_INVITE, false)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
team *model.Team
|
||||
privacy string
|
||||
errChecker func(t *testing.T, resp *model.Response)
|
||||
wantType string
|
||||
wantOpenInvite bool
|
||||
}{
|
||||
{name: "bad privacy", team: teamPublic, privacy: "blap", errChecker: CheckBadRequestStatus, wantType: model.TEAM_OPEN, wantOpenInvite: true},
|
||||
{name: "bad team", team: &model.Team{Id: model.NewId()}, privacy: model.TEAM_OPEN, errChecker: CheckForbiddenStatus, wantType: model.TEAM_OPEN, wantOpenInvite: true},
|
||||
{name: "public to private", team: teamPublic, privacy: model.TEAM_INVITE, errChecker: nil, wantType: model.TEAM_INVITE, wantOpenInvite: false},
|
||||
{name: "private to public", team: teamPrivate, privacy: model.TEAM_OPEN, errChecker: nil, wantType: model.TEAM_OPEN, wantOpenInvite: true},
|
||||
{name: "public to public", team: teamPublic2, privacy: model.TEAM_OPEN, errChecker: nil, wantType: model.TEAM_OPEN, wantOpenInvite: true},
|
||||
{name: "private to private", team: teamPrivate2, privacy: model.TEAM_INVITE, errChecker: nil, wantType: model.TEAM_INVITE, wantOpenInvite: false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
team, resp := Client.UpdateTeamPrivacy(test.team.Id, test.privacy)
|
||||
if test.errChecker != nil {
|
||||
test.errChecker(t, resp)
|
||||
return
|
||||
} else {
|
||||
CheckNoError(t, resp)
|
||||
CheckOKStatus(t, resp)
|
||||
}
|
||||
require.Equal(t, test.wantType, team.Type)
|
||||
require.Equal(t, test.wantOpenInvite, team.AllowOpenInvite)
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("not logged in", func(t *testing.T) {
|
||||
Client.Logout()
|
||||
_, resp := Client.UpdateTeamPrivacy(teamPublic.Id, model.TEAM_INVITE)
|
||||
CheckUnauthorizedStatus(t, resp)
|
||||
})
|
||||
|
||||
t.Run("no permission to manage team", func(t *testing.T) {
|
||||
th.LoginBasic2()
|
||||
_, resp := Client.UpdateTeamPrivacy(teamPublic.Id, model.TEAM_INVITE)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTeamUnicodeNames(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
Ссылка в новой задаче
Block a user