Include deleted channels on get user channels endpoint (#13877)

Этот коммит содержится в:
Mario de Frutos Dieguez
2020-03-02 22:15:15 +01:00
коммит произвёл GitHub
родитель 8f0bedf9c9
Коммит a43439dd60
6 изменённых файлов: 101 добавлений и 56 удалений

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

@@ -107,6 +107,7 @@ func TestMoveChannel(t *testing.T) {
// It should fail, unless removeDeactivatedMembers is true.
deacivatedUser := th.CreateUser()
channel2 := th.CreateChannel(sourceTeam)
defer th.App.PermanentDeleteChannel(channel2)
_, err = th.App.AddUserToTeam(sourceTeam.Id, deacivatedUser.Id, "")
require.Nil(t, err)
@@ -136,6 +137,7 @@ func TestMoveChannel(t *testing.T) {
channel3, err = th.App.CreateChannel(channel3, false)
require.Nil(t, err)
defer th.App.PermanentDeleteChannel(channel3)
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser, false)
assert.Nil(t, err)
@@ -208,6 +210,7 @@ func TestJoinDefaultChannelsExperimentalDefaultChannels(t *testing.T) {
defer th.TearDown()
basicChannel2 := th.CreateChannel(th.BasicTeam)
defer th.App.PermanentDeleteChannel(basicChannel2)
defaultChannelList := []string{th.BasicChannel.Name, basicChannel2.Name, basicChannel2.Name}
th.App.Config().TeamSettings.ExperimentalDefaultChannels = defaultChannelList
@@ -259,6 +262,7 @@ func TestCreateChannelDisplayNameTrimsWhitespace(t *testing.T) {
defer th.TearDown()
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: " Public 1 ", Name: "public1", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
defer th.App.PermanentDeleteChannel(channel)
require.Nil(t, err)
require.Equal(t, channel.DisplayName, "Public 1")
}
@@ -390,30 +394,6 @@ func TestAddUserToChannelCreatesChannelMemberHistoryRecord(t *testing.T) {
assert.Equal(t, groupUserIds, channelMemberHistoryUserIds)
}
/*func TestRemoveUserFromChannelUpdatesChannelMemberHistoryRecord(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
// a user creates a channel
publicChannel := th.createChannel(th.BasicTeam, model.CHANNEL_OPEN)
histories, err := th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)
require.Nil(t, err)
assert.Len(t, histories, 1)
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
assert.Equal(t, publicChannel.Id, histories[0].ChannelId)
assert.Nil(t, histories[0].LeaveTime)
// the user leaves that channel
if err := th.App.LeaveChannel(publicChannel.Id, th.BasicUser.Id); err != nil {
require.Fail(t, "Failed to remove user from channel. Error: " + err.Message)
}
histories = store.Must(th.App.Srv().Store.ChannelMemberHistory().GetUsersInChannelDuring(model.GetMillis()-100, model.GetMillis()+100, publicChannel.Id)).([]*model.ChannelMemberHistoryResult)
assert.Len(t, histories, 1)
assert.Equal(t, th.BasicUser.Id, histories[0].UserId)
assert.Equal(t, publicChannel.Id, histories[0].ChannelId)
assert.NotNil(t, histories[0].LeaveTime)
}*/
func TestLeaveDefaultChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
@@ -828,6 +808,36 @@ func TestGetChannelMembersTimezones(t *testing.T) {
assert.Equal(t, 2, len(timezones))
}
func TestGetChannelsForUser(t *testing.T) {
th := Setup(t).InitBasic()
channel := &model.Channel{
DisplayName: fmt.Sprintf("Public"),
Name: fmt.Sprintf("public"),
Type: model.CHANNEL_OPEN,
CreatorId: th.BasicUser.Id,
TeamId: th.BasicTeam.Id,
}
th.App.CreateChannel(channel, true)
defer th.App.PermanentDeleteChannel(channel)
defer th.TearDown()
channelList, err := th.App.GetChannelsForUser(th.BasicTeam.Id, th.BasicUser.Id, false)
require.Nil(t, err)
require.Len(t, *channelList, 4)
th.App.DeleteChannel(channel, th.BasicUser.Id)
// Now we get all the non-archived channels for the user
channelList, err = th.App.GetChannelsForUser(th.BasicTeam.Id, th.BasicUser.Id, false)
require.Nil(t, err)
require.Len(t, *channelList, 3)
// Now we get all the channels, even though are archived, for the user
channelList, err = th.App.GetChannelsForUser(th.BasicTeam.Id, th.BasicUser.Id, true)
require.Nil(t, err)
require.Len(t, *channelList, 4)
}
func TestGetPublicChannelsForTeam(t *testing.T) {
th := Setup(t)
team := th.CreateTeam()