[MM-51089] Fix sorting value of category in CreateSidebarCategoryForTeamForUser (#22455)

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Tanmay Datta
2023-04-19 14:59:49 +01:00
коммит произвёл yasserfaraazkhan
родитель afa3a7eb8f
Коммит 5beaee031d
2 изменённых файлов: 33 добавлений и 1 удалений

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

@@ -335,7 +335,7 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
Id: newCategoryId,
UserId: userId,
TeamId: teamId,
Sorting: model.SidebarCategorySortDefault,
Sorting: newCategory.Sorting,
SortOrder: int64(model.MinimalSidebarSortDistance * len(newOrder)), // first we place it at the end of the list
Type: model.SidebarCategoryCustom,
Muted: newCategory.Muted,

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

@@ -672,6 +672,38 @@ func testCreateSidebarCategory(t *testing.T, ss store.Store) {
require.NoError(t, err)
assert.Equal(t, []string{}, res2.Channels)
})
t.Run("should store the correct sorting value", func(t *testing.T) {
userId := model.NewId()
team := setupTeam(t, ss, userId)
opts := &store.SidebarCategorySearchOpts{
TeamID: team.Id,
ExcludeTeam: false,
}
res, nErr := ss.Channel().CreateInitialSidebarCategories(userId, opts)
require.NoError(t, nErr)
require.NotEmpty(t, res)
// Create the category
created, err := ss.Channel().CreateSidebarCategory(userId, team.Id, &model.SidebarCategoryWithChannels{
SidebarCategory: model.SidebarCategory{
DisplayName: model.NewId(),
Sorting: model.SidebarCategorySortManual,
},
})
require.NoError(t, err)
// Confirm that sorting value is correct
res, err = ss.Channel().GetSidebarCategoriesForTeamForUser(userId, team.Id)
require.NoError(t, err)
require.Len(t, res.Categories, 4)
// first category will be favorites and second will be newly created
assert.Equal(t, model.SidebarCategoryCustom, res.Categories[1].Type)
assert.Equal(t, created.Id, res.Categories[1].Id)
assert.Equal(t, model.SidebarCategorySortManual, res.Categories[1].Sorting)
assert.Equal(t, model.SidebarCategorySortManual, created.Sorting)
})
}
func testGetSidebarCategory(t *testing.T, ss store.Store, s SqlStore) {