MM-26871 Add test for sidebar when moving channels between teams (#15021)

* MM-26871 Add test for sidebar when moving channels between teams

* Change require.NotNil to require.Error
Этот коммит содержится в:
Harrison Healey
2020-07-17 15:56:02 -04:00
коммит произвёл GitHub
родитель fe45e0a98b
Коммит 9805a594dd

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

@@ -103,78 +103,121 @@ func TestRemoveAllDeactivatedMembersFromChannel(t *testing.T) {
}
func TestMoveChannel(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
var err *model.AppError
t.Run("should move channels between teams", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
var err *model.AppError
sourceTeam := th.CreateTeam()
targetTeam := th.CreateTeam()
channel1 := th.CreateChannel(sourceTeam)
defer func() {
th.App.PermanentDeleteChannel(channel1)
th.App.PermanentDeleteTeam(sourceTeam)
th.App.PermanentDeleteTeam(targetTeam)
}()
sourceTeam := th.CreateTeam()
targetTeam := th.CreateTeam()
channel1 := th.CreateChannel(sourceTeam)
defer func() {
th.App.PermanentDeleteChannel(channel1)
th.App.PermanentDeleteTeam(sourceTeam)
th.App.PermanentDeleteTeam(targetTeam)
}()
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToChannel(th.BasicUser, channel1)
require.Nil(t, err)
_, err = th.App.AddUserToChannel(th.BasicUser, channel1)
require.Nil(t, err)
_, err = th.App.AddUserToChannel(th.BasicUser2, channel1)
require.Nil(t, err)
_, err = th.App.AddUserToChannel(th.BasicUser2, channel1)
require.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
require.NotNil(t, err, "Should have failed due to mismatched members.")
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
require.Error(t, err, "Should have failed due to mismatched members.")
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, "")
require.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
require.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
require.Nil(t, err)
// Test moving a channel with a deactivated user who isn't in the destination team.
// It should fail, unless removeDeactivatedMembers is true.
deacivatedUser := th.CreateUser()
channel2 := th.CreateChannel(sourceTeam)
defer th.App.PermanentDeleteChannel(channel2)
// Test moving a channel with a deactivated user who isn't in the destination team.
// 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)
_, err = th.App.AddUserToChannel(th.BasicUser, channel2)
require.Nil(t, err)
_, err = th.App.AddUserToTeam(sourceTeam.Id, deacivatedUser.Id, "")
require.Nil(t, err)
_, err = th.App.AddUserToChannel(th.BasicUser, channel2)
require.Nil(t, err)
_, err = th.App.AddUserToChannel(deacivatedUser, channel2)
require.Nil(t, err)
_, err = th.App.AddUserToChannel(deacivatedUser, channel2)
require.Nil(t, err)
_, err = th.App.UpdateActive(deacivatedUser, false)
require.Nil(t, err)
_, err = th.App.UpdateActive(deacivatedUser, false)
require.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel2, th.BasicUser)
require.NotNil(t, err, "Should have failed due to mismatched deacivated member.")
err = th.App.MoveChannel(targetTeam, channel2, th.BasicUser)
require.Error(t, err, "Should have failed due to mismatched deacivated member.")
// Test moving a channel with no members.
channel3 := &model.Channel{
DisplayName: "dn_" + model.NewId(),
Name: "name_" + model.NewId(),
Type: model.CHANNEL_OPEN,
TeamId: sourceTeam.Id,
CreatorId: th.BasicUser.Id,
}
// Test moving a channel with no members.
channel3 := &model.Channel{
DisplayName: "dn_" + model.NewId(),
Name: "name_" + model.NewId(),
Type: model.CHANNEL_OPEN,
TeamId: sourceTeam.Id,
CreatorId: th.BasicUser.Id,
}
channel3, err = th.App.CreateChannel(channel3, false)
require.Nil(t, err)
defer th.App.PermanentDeleteChannel(channel3)
channel3, err = th.App.CreateChannel(channel3, false)
require.Nil(t, err)
defer th.App.PermanentDeleteChannel(channel3)
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser)
assert.Nil(t, err)
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser)
assert.Nil(t, err)
})
t.Run("should remove sidebar entries when moving channels from one team to another", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
sourceTeam := th.CreateTeam()
targetTeam := th.CreateTeam()
channel := th.CreateChannel(sourceTeam)
th.LinkUserToTeam(th.BasicUser, sourceTeam)
th.LinkUserToTeam(th.BasicUser, targetTeam)
th.AddUserToChannel(th.BasicUser, channel)
// Put the channel in a custom category so that it explicitly exists in SidebarChannels
category, err := th.App.CreateSidebarCategory(th.BasicUser.Id, sourceTeam.Id, &model.SidebarCategoryWithChannels{
SidebarCategory: model.SidebarCategory{
DisplayName: "new category",
},
Channels: []string{channel.Id},
})
require.Nil(t, err)
require.Equal(t, []string{channel.Id}, category.Channels)
err = th.App.MoveChannel(targetTeam, channel, th.BasicUser)
require.Nil(t, err)
moved, err := th.App.GetChannel(channel.Id)
require.Nil(t, err)
require.Equal(t, targetTeam.Id, moved.TeamId)
// The channel should no longer be on the old team
updatedCategory, err := th.App.GetSidebarCategory(category.Id)
require.Nil(t, err)
assert.Equal(t, []string{}, updatedCategory.Channels)
// And it should be on the new team instead
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, targetTeam.Id)
require.Nil(t, err)
require.Equal(t, model.SidebarCategoryChannels, categories.Categories[1].Type)
assert.Contains(t, categories.Categories[1].Channels, channel.Id)
})
}
func TestRemoveUsersFromChannelNotMemberOfTeam(t *testing.T) {