MM-51482_Create Apps Category and link to bots DM (#22918)

Этот коммит содержится в:
Julian Mondragón
2023-04-27 19:44:14 -05:00
коммит произвёл GitHub
родитель 13f1d0fdc5
Коммит 1051925eec
17 изменённых файлов: 3650 добавлений и 113 удалений

Просмотреть файл

@@ -1025,6 +1025,119 @@ func TestJoinUserToTeam(t *testing.T) {
})
}
func TestJoinUserToTeamWithAppsCategoryEnabled(t *testing.T) {
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) { cfg.FeatureFlags.AppsSidebarCategory = true })
id := model.NewId()
team := &model.Team{
DisplayName: "dn_" + id,
Name: "name" + id,
Email: "success+" + id + "@simulator.amazonses.com",
Type: model.TeamOpen,
}
_, err := th.App.CreateTeam(th.Context, team)
require.Nil(t, err, "Should create a new team")
maxUsersPerTeam := th.App.Config().TeamSettings.MaxUsersPerTeam
defer func() {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = maxUsersPerTeam })
th.App.PermanentDeleteTeam(th.Context, team)
}()
one := 1
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = &one })
t.Run("new join", func(t *testing.T) {
user := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser, _ := th.App.CreateUser(th.Context, &user)
defer th.App.PermanentDeleteUser(th.Context, &user)
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser, "")
require.Nil(t, appErr, "Should return no error")
})
t.Run("new join with limit problem", func(t *testing.T) {
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser1, _ := th.App.CreateUser(th.Context, &user1)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser2, _ := th.App.CreateUser(th.Context, &user2)
defer th.App.PermanentDeleteUser(th.Context, &user1)
defer th.App.PermanentDeleteUser(th.Context, &user2)
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
require.Nil(t, appErr, "Should return no error")
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser2, ruser1.Id)
require.NotNil(t, appErr, "Should fail")
})
t.Run("re-join after leaving with limit problem", func(t *testing.T) {
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser1, _ := th.App.CreateUser(th.Context, &user1)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser2, _ := th.App.CreateUser(th.Context, &user2)
defer th.App.PermanentDeleteUser(th.Context, &user1)
defer th.App.PermanentDeleteUser(th.Context, &user2)
_, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
require.Nil(t, appErr, "Should return no error")
appErr = th.App.LeaveTeam(th.Context, team, ruser1, ruser1.Id)
require.Nil(t, appErr, "Should return no error")
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser2, ruser2.Id)
require.Nil(t, appErr, "Should return no error")
_, appErr = th.App.JoinUserToTeam(th.Context, team, ruser1, ruser2.Id)
require.NotNil(t, appErr, "Should fail")
})
t.Run("new join with correct scheme_admin value from group syncable", func(t *testing.T) {
user1 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser1, _ := th.App.CreateUser(th.Context, &user1)
defer th.App.PermanentDeleteUser(th.Context, &user1)
group := th.CreateGroup()
_, err = th.App.UpsertGroupMember(group.Id, user1.Id)
require.Nil(t, err)
gs, err := th.App.UpsertGroupSyncable(&model.GroupSyncable{
AutoAdd: true,
SyncableId: team.Id,
Type: model.GroupSyncableTypeTeam,
GroupId: group.Id,
SchemeAdmin: false,
})
require.Nil(t, err)
th.App.UpdateConfig(func(cfg *model.Config) { cfg.TeamSettings.MaxUsersPerTeam = model.NewInt(999) })
tm1, appErr := th.App.JoinUserToTeam(th.Context, team, ruser1, "")
require.Nil(t, appErr)
require.False(t, tm1.SchemeAdmin)
user2 := model.User{Email: strings.ToLower(model.NewId()) + "success+test@example.com", Nickname: "Darth Vader", Username: "vader" + model.NewId(), Password: "passwd1", AuthService: ""}
ruser2, _ := th.App.CreateUser(th.Context, &user2)
defer th.App.PermanentDeleteUser(th.Context, &user2)
_, err = th.App.UpsertGroupMember(group.Id, user2.Id)
require.Nil(t, err)
gs.SchemeAdmin = true
_, err = th.App.UpdateGroupSyncable(gs)
require.Nil(t, err)
tm2, appErr := th.App.JoinUserToTeam(th.Context, team, ruser2, "")
require.Nil(t, appErr)
require.True(t, tm2.SchemeAdmin)
})
}
func TestLeaveTeamPanic(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()