MM-26753 Create initial sidebar categories on demand if migration hasn't ran (#14981)

* MM-26753 Change CreateInitialSidebarCategories to only take a user ID

* MM-26753 Create initial sidebar categories on demand if migration hasn't ran

* Wait for sidebar categories to be loaded in case of replication lag
Этот коммит содержится в:
Harrison Healey
2020-07-08 12:07:42 -04:00
коммит произвёл GitHub
родитель 31200fc657
Коммит 302e59a0fe
10 изменённых файлов: 219 добавлений и 167 удалений

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

@@ -1858,3 +1858,42 @@ func TestSidebarCategory(t *testing.T) {
require.Equal(t, catOrder[1], createdCategory.Id, "the newly created category should be after favorites")
})
}
func TestGetSidebarCategories(t *testing.T) {
t.Run("should return the sidebar categories for the given user/team", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
_, err := th.App.CreateSidebarCategory(th.BasicUser.Id, th.BasicTeam.Id, &model.SidebarCategoryWithChannels{
SidebarCategory: model.SidebarCategory{
UserId: th.BasicUser.Id,
TeamId: th.BasicTeam.Id,
DisplayName: "new category",
},
})
require.Nil(t, err)
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
assert.Nil(t, err)
assert.Len(t, categories.Categories, 4)
})
t.Run("should create the initial categories even if migration hasn't ran yet", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
// Manually add the user to the team without going through the app layer to simulate a pre-existing user/team
// relationship that hasn't been migrated yet
team := th.CreateTeam()
_, err := th.App.Srv().Store.Team().SaveMember(&model.TeamMember{
TeamId: team.Id,
UserId: th.BasicUser.Id,
SchemeUser: true,
}, 100)
require.Nil(t, err)
categories, err := th.App.GetSidebarCategories(th.BasicUser.Id, team.Id)
assert.Nil(t, err)
assert.Len(t, categories.Categories, 3)
})
}