Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e9f6e127a4
Коммит
9f54e5cdc3
@@ -2467,7 +2467,7 @@ func getGroupMessageMembersCommonTeams(c *Context, w http.ResponseWriter, r *htt
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewEncoder(w).Encode(teams); err != nil {
|
if err := json.NewEncoder(w).Encode(c.App.SanitizeTeams(*c.AppContext.Session(), teams)); err != nil {
|
||||||
c.Logger.Warn("Error while writing response from getGroupMessageMembersCommonTeams", mlog.Err(err))
|
c.Logger.Warn("Error while writing response from getGroupMessageMembersCommonTeams", mlog.Err(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2863,69 +2863,61 @@ func TestIsCRTEnabledForUser(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetGroupMessageMembersCommonTeams(t *testing.T) {
|
func TestGetGroupMessageMembersCommonTeams(t *testing.T) {
|
||||||
mainHelper.Parallel(t)
|
mainHelper.Parallel(t)
|
||||||
th := SetupWithStoreMock(t)
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
mockStore := th.App.Srv().Store().(*mocks.Store)
|
teamsToCreate := 2
|
||||||
|
usersToCreate := 4 // at least 3 users to create a GM channel, last user is not in any team
|
||||||
mockChannelStore := mocks.ChannelStore{}
|
teams := make([]string, 0, teamsToCreate)
|
||||||
mockStore.On("Channel").Return(&mockChannelStore)
|
for i := 0; i < cap(teams); i++ {
|
||||||
mockChannelStore.On("Get", "gm_channel_id", true).Return(&model.Channel{Type: model.ChannelTypeGroup}, nil)
|
team := th.CreateTeam()
|
||||||
|
defer func(team *model.Team) {
|
||||||
mockTeamStore := mocks.TeamStore{}
|
appErr := th.App.PermanentDeleteTeam(th.Context, team)
|
||||||
mockStore.On("Team").Return(&mockTeamStore)
|
require.Nil(t, appErr)
|
||||||
|
}(team)
|
||||||
th.App.Srv().Store().Team()
|
teams = append(teams, team.Id)
|
||||||
|
|
||||||
mockTeamStore.On("GetCommonTeamIDsForMultipleUsers", []string{"user_id_1", "user_id_2"}).Return([]string{"team_id_1", "team_id_2", "team_id_3"}, nil).Times(1)
|
|
||||||
mockTeamStore.On("GetMany", []string{"team_id_1", "team_id_2", "team_id_3"}).Return(
|
|
||||||
[]*model.Team{
|
|
||||||
{DisplayName: "Team 1"},
|
|
||||||
{DisplayName: "Team 2"},
|
|
||||||
{DisplayName: "Team 3"},
|
|
||||||
},
|
|
||||||
nil,
|
|
||||||
)
|
|
||||||
|
|
||||||
mockUserStore := mocks.UserStore{}
|
|
||||||
mockStore.On("User").Return(&mockUserStore)
|
|
||||||
options := &model.UserGetOptions{
|
|
||||||
PerPage: model.ChannelGroupMaxUsers,
|
|
||||||
Page: 0,
|
|
||||||
InChannelId: "gm_channel_id",
|
|
||||||
Inactive: false,
|
|
||||||
Active: true,
|
|
||||||
}
|
}
|
||||||
mockUserStore.On("GetProfilesInChannel", options).Return([]*model.User{
|
|
||||||
{
|
|
||||||
Id: "user_id_1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Id: "user_id_2",
|
|
||||||
},
|
|
||||||
}, nil)
|
|
||||||
|
|
||||||
var err error
|
users := make([]string, 0, usersToCreate)
|
||||||
th.App.ch.srv.teamService, err = teams.New(teams.ServiceConfig{
|
for i := 0; i < cap(users); i++ {
|
||||||
TeamStore: &mockTeamStore,
|
user := th.CreateUser()
|
||||||
ChannelStore: &mockChannelStore,
|
defer func(user *model.User) {
|
||||||
GroupStore: &mocks.GroupStore{},
|
appErr := th.App.PermanentDeleteUser(th.Context, user)
|
||||||
Users: th.App.ch.srv.userService,
|
require.Nil(t, appErr)
|
||||||
WebHub: th.App.ch.srv.platform,
|
}(user)
|
||||||
ConfigFn: th.App.ch.srv.platform.Config,
|
users = append(users, user.Id)
|
||||||
LicenseFn: th.App.ch.srv.License,
|
}
|
||||||
|
|
||||||
|
for _, teamId := range teams {
|
||||||
|
// add first 3 users to each team, last user is not in any team
|
||||||
|
for i := range 3 {
|
||||||
|
_, _, appErr := th.App.AddUserToTeam(th.Context, teamId, users[i], "")
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create GM channel with first 3 users who share common teams
|
||||||
|
gmChannel, appErr := th.App.createGroupChannel(th.Context, users[:3], users[0])
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
require.NotNil(t, gmChannel)
|
||||||
|
|
||||||
|
// normally you can't create a GM channel with users that don't share any teams, but we do it here to test the edge case
|
||||||
|
// create GM channel with last 3 users, where last member is not in any team
|
||||||
|
otherGMChannel, appErr := th.App.createGroupChannel(th.Context, users[1:], users[0])
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
require.NotNil(t, otherGMChannel)
|
||||||
|
|
||||||
|
t.Run("Get teams for GM channel", func(t *testing.T) {
|
||||||
|
commonTeams, appErr := th.App.GetGroupMessageMembersCommonTeams(th.Context, gmChannel.Id)
|
||||||
|
require.Nil(t, appErr)
|
||||||
|
require.Equal(t, 2, len(commonTeams))
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
commonTeams, appErr := th.App.GetGroupMessageMembersCommonTeams(th.Context, "gm_channel_id")
|
t.Run("No common teams", func(t *testing.T) {
|
||||||
require.Nil(t, appErr)
|
commonTeams, appErr := th.App.GetGroupMessageMembersCommonTeams(th.Context, otherGMChannel.Id)
|
||||||
require.Equal(t, 3, len(commonTeams))
|
require.Nil(t, appErr)
|
||||||
|
require.Equal(t, 0, len(commonTeams))
|
||||||
// case of no common teams
|
})
|
||||||
mockTeamStore.On("GetCommonTeamIDsForMultipleUsers", []string{"user_id_1", "user_id_2"}).Return([]string{}, nil)
|
|
||||||
commonTeams, appErr = th.App.GetGroupMessageMembersCommonTeams(th.Context, "gm_channel_id")
|
|
||||||
require.Nil(t, appErr)
|
|
||||||
require.Equal(t, 0, len(commonTeams))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConvertGroupMessageToChannel(t *testing.T) {
|
func TestConvertGroupMessageToChannel(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user