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
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
fe45e0a98b
Коммит
9805a594dd
@@ -103,78 +103,121 @@ func TestRemoveAllDeactivatedMembersFromChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveChannel(t *testing.T) {
|
func TestMoveChannel(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
t.Run("should move channels between teams", func(t *testing.T) {
|
||||||
defer th.TearDown()
|
th := Setup(t).InitBasic()
|
||||||
var err *model.AppError
|
defer th.TearDown()
|
||||||
|
var err *model.AppError
|
||||||
|
|
||||||
sourceTeam := th.CreateTeam()
|
sourceTeam := th.CreateTeam()
|
||||||
targetTeam := th.CreateTeam()
|
targetTeam := th.CreateTeam()
|
||||||
channel1 := th.CreateChannel(sourceTeam)
|
channel1 := th.CreateChannel(sourceTeam)
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.PermanentDeleteChannel(channel1)
|
th.App.PermanentDeleteChannel(channel1)
|
||||||
th.App.PermanentDeleteTeam(sourceTeam)
|
th.App.PermanentDeleteTeam(sourceTeam)
|
||||||
th.App.PermanentDeleteTeam(targetTeam)
|
th.App.PermanentDeleteTeam(targetTeam)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, "")
|
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, "")
|
_, err = th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, "")
|
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.AddUserToChannel(th.BasicUser, channel1)
|
_, err = th.App.AddUserToChannel(th.BasicUser, channel1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.AddUserToChannel(th.BasicUser2, channel1)
|
_, err = th.App.AddUserToChannel(th.BasicUser2, channel1)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
|
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
|
||||||
require.NotNil(t, err, "Should have failed due to mismatched members.")
|
require.Error(t, err, "Should have failed due to mismatched members.")
|
||||||
|
|
||||||
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, "")
|
_, err = th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
|
err = th.App.MoveChannel(targetTeam, channel1, th.BasicUser)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
// Test moving a channel with a deactivated user who isn't in the destination team.
|
// Test moving a channel with a deactivated user who isn't in the destination team.
|
||||||
// It should fail, unless removeDeactivatedMembers is true.
|
// It should fail, unless removeDeactivatedMembers is true.
|
||||||
deacivatedUser := th.CreateUser()
|
deacivatedUser := th.CreateUser()
|
||||||
channel2 := th.CreateChannel(sourceTeam)
|
channel2 := th.CreateChannel(sourceTeam)
|
||||||
defer th.App.PermanentDeleteChannel(channel2)
|
defer th.App.PermanentDeleteChannel(channel2)
|
||||||
|
|
||||||
_, err = th.App.AddUserToTeam(sourceTeam.Id, deacivatedUser.Id, "")
|
_, err = th.App.AddUserToTeam(sourceTeam.Id, deacivatedUser.Id, "")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
_, err = th.App.AddUserToChannel(th.BasicUser, channel2)
|
_, err = th.App.AddUserToChannel(th.BasicUser, channel2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.AddUserToChannel(deacivatedUser, channel2)
|
_, err = th.App.AddUserToChannel(deacivatedUser, channel2)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
_, err = th.App.UpdateActive(deacivatedUser, false)
|
_, err = th.App.UpdateActive(deacivatedUser, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
err = th.App.MoveChannel(targetTeam, channel2, th.BasicUser)
|
err = th.App.MoveChannel(targetTeam, channel2, th.BasicUser)
|
||||||
require.NotNil(t, err, "Should have failed due to mismatched deacivated member.")
|
require.Error(t, err, "Should have failed due to mismatched deacivated member.")
|
||||||
|
|
||||||
// Test moving a channel with no members.
|
// Test moving a channel with no members.
|
||||||
channel3 := &model.Channel{
|
channel3 := &model.Channel{
|
||||||
DisplayName: "dn_" + model.NewId(),
|
DisplayName: "dn_" + model.NewId(),
|
||||||
Name: "name_" + model.NewId(),
|
Name: "name_" + model.NewId(),
|
||||||
Type: model.CHANNEL_OPEN,
|
Type: model.CHANNEL_OPEN,
|
||||||
TeamId: sourceTeam.Id,
|
TeamId: sourceTeam.Id,
|
||||||
CreatorId: th.BasicUser.Id,
|
CreatorId: th.BasicUser.Id,
|
||||||
}
|
}
|
||||||
|
|
||||||
channel3, err = th.App.CreateChannel(channel3, false)
|
channel3, err = th.App.CreateChannel(channel3, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
defer th.App.PermanentDeleteChannel(channel3)
|
defer th.App.PermanentDeleteChannel(channel3)
|
||||||
|
|
||||||
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser)
|
err = th.App.MoveChannel(targetTeam, channel3, th.BasicUser)
|
||||||
assert.Nil(t, err)
|
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) {
|
func TestRemoveUsersFromChannelNotMemberOfTeam(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user