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,6 +103,7 @@ func TestRemoveAllDeactivatedMembersFromChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMoveChannel(t *testing.T) {
|
func TestMoveChannel(t *testing.T) {
|
||||||
|
t.Run("should move channels between teams", func(t *testing.T) {
|
||||||
th := Setup(t).InitBasic()
|
th := Setup(t).InitBasic()
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
var err *model.AppError
|
var err *model.AppError
|
||||||
@@ -132,7 +133,7 @@ func TestMoveChannel(t *testing.T) {
|
|||||||
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)
|
||||||
@@ -158,7 +159,7 @@ func TestMoveChannel(t *testing.T) {
|
|||||||
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{
|
||||||
@@ -175,6 +176,48 @@ func TestMoveChannel(t *testing.T) {
|
|||||||
|
|
||||||
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