[MM-35316] Fix panic in app.CreateSidebarCategory (#17546)
* Fix returned error * Fix expected error
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e414efac63
Коммит
a7e6eef836
@@ -248,10 +248,8 @@ func (s SqlChannelStore) CreateSidebarCategory(userId, teamId string, newCategor
|
|||||||
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, teamId)
|
categoriesWithOrder, err := s.getSidebarCategoriesT(transaction, userId, teamId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
} else if len(categoriesWithOrder.Categories) == 0 {
|
||||||
|
return nil, store.NewErrNotFound("categories not found", fmt.Sprintf("userId=%s,teamId=%s", userId, teamId))
|
||||||
if len(categoriesWithOrder.Categories) < 1 {
|
|
||||||
return nil, errors.Wrap(err, "categories not found")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newOrder := categoriesWithOrder.Order
|
newOrder := categoriesWithOrder.Order
|
||||||
@@ -480,6 +478,7 @@ func (s SqlChannelStore) getSidebarCategoriesT(db dbSelecter, userId, teamId str
|
|||||||
if _, err = db.Select(&categories, query, args...); err != nil {
|
if _, err = db.Select(&categories, query, args...); err != nil {
|
||||||
return nil, store.NewErrNotFound("SidebarCategories", fmt.Sprintf("userId=%s,teamId=%s", userId, teamId))
|
return nil, store.NewErrNotFound("SidebarCategories", fmt.Sprintf("userId=%s,teamId=%s", userId, teamId))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, category := range categories {
|
for _, category := range categories {
|
||||||
var prevCategory *model.SidebarCategoryWithChannels
|
var prevCategory *model.SidebarCategoryWithChannels
|
||||||
for _, existing := range oc.Categories {
|
for _, existing := range oc.Categories {
|
||||||
|
|||||||
@@ -363,6 +363,22 @@ func testCreateInitialSidebarCategories(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
func testCreateSidebarCategory(t *testing.T, ss store.Store) {
|
||||||
|
t.Run("Creating category without initial categories should fail", func(t *testing.T) {
|
||||||
|
userId := model.NewId()
|
||||||
|
teamId := model.NewId()
|
||||||
|
|
||||||
|
// Create the category
|
||||||
|
created, err := ss.Channel().CreateSidebarCategory(userId, teamId, &model.SidebarCategoryWithChannels{
|
||||||
|
SidebarCategory: model.SidebarCategory{
|
||||||
|
DisplayName: model.NewId(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
require.Error(t, err)
|
||||||
|
var errNotFound *store.ErrNotFound
|
||||||
|
require.ErrorAs(t, err, &errNotFound)
|
||||||
|
require.Nil(t, created)
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("should place the new category second if Favorites comes first", func(t *testing.T) {
|
t.Run("should place the new category second if Favorites comes first", func(t *testing.T) {
|
||||||
userId := model.NewId()
|
userId := model.NewId()
|
||||||
teamId := model.NewId()
|
teamId := model.NewId()
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user