Move channel category code into its own files (#15319)
* Move channel category code into its own files * Move channel category tests into app/channel_category_test.go
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7fe6c94eda
Коммит
52611a1761
105
app/channel.go
105
app/channel.go
@@ -2630,108 +2630,3 @@ func (a *App) ClearChannelMembersCache(channelID string) {
|
||||
page++
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) createInitialSidebarCategories(userId, teamId string) *model.AppError {
|
||||
nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
|
||||
if nErr != nil {
|
||||
return model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
nErr := a.createInitialSidebarCategories(userId, teamId)
|
||||
if nErr != nil {
|
||||
return nil, nErr
|
||||
}
|
||||
|
||||
categories, err = a.waitForSidebarCategories(userId, teamId)
|
||||
}
|
||||
|
||||
return categories, err
|
||||
}
|
||||
|
||||
// waitForSidebarCategories is used to get a user's sidebar categories after they've been created since there may be
|
||||
// replication lag if any database replicas exist. It will wait until results are available to return them.
|
||||
func (a *App) waitForSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||
// The categories should be available immediately on a single database
|
||||
return a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
}
|
||||
|
||||
now := model.GetMillis()
|
||||
|
||||
for model.GetMillis()-now < 12000 {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
|
||||
if err != nil || len(categories.Categories) > 0 {
|
||||
// We've found something, so return
|
||||
return categories, err
|
||||
}
|
||||
}
|
||||
|
||||
mlog.Error("waitForSidebarCategories giving up", mlog.String("user_id", userId), mlog.String("team_id", teamId))
|
||||
|
||||
return &model.OrderedSidebarCategories{}, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategoryOrder(userId, teamId string) ([]string, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategoryOrder(userId, teamId)
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategory(categoryId)
|
||||
}
|
||||
|
||||
func (a *App) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store.Channel().CreateSidebarCategory(userId, teamId, newCategory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_CREATED, teamId, "", userId, nil)
|
||||
message.Add("category_id", category.Id)
|
||||
a.Publish(message)
|
||||
return category, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().UpdateSidebarCategoryOrder(userId, teamId, categoryOrder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_ORDER_UPDATED, teamId, "", userId, nil)
|
||||
message.Add("order", categoryOrder)
|
||||
a.Publish(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
result, err := a.Srv().Store.Channel().UpdateSidebarCategories(userId, teamId, categories)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_UPDATED, teamId, "", userId, nil)
|
||||
a.Publish(message)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *App) DeleteSidebarCategory(userId, teamId, categoryId string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().DeleteSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_DELETED, teamId, "", userId, nil)
|
||||
message.Add("category_id", categoryId)
|
||||
a.Publish(message)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
117
app/channel_category.go
Обычный файл
117
app/channel_category.go
Обычный файл
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
func (a *App) createInitialSidebarCategories(userId, teamId string) *model.AppError {
|
||||
nErr := a.Srv().Store.Channel().CreateInitialSidebarCategories(userId, teamId)
|
||||
|
||||
if nErr != nil {
|
||||
return model.NewAppError("createInitialSidebarCategories", "app.channel.create_initial_sidebar_categories.internal_error", nil, nErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
|
||||
if err == nil && len(categories.Categories) == 0 {
|
||||
// A user must always have categories, so migration must not have happened yet, and we should run it ourselves
|
||||
nErr := a.createInitialSidebarCategories(userId, teamId)
|
||||
if nErr != nil {
|
||||
return nil, nErr
|
||||
}
|
||||
|
||||
categories, err = a.waitForSidebarCategories(userId, teamId)
|
||||
}
|
||||
|
||||
return categories, err
|
||||
}
|
||||
|
||||
// waitForSidebarCategories is used to get a user's sidebar categories after they've been created since there may be
|
||||
// replication lag if any database replicas exist. It will wait until results are available to return them.
|
||||
func (a *App) waitForSidebarCategories(userId, teamId string) (*model.OrderedSidebarCategories, *model.AppError) {
|
||||
if len(a.Config().SqlSettings.DataSourceReplicas) == 0 {
|
||||
// The categories should be available immediately on a single database
|
||||
return a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
}
|
||||
|
||||
now := model.GetMillis()
|
||||
|
||||
for model.GetMillis()-now < 12000 {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
categories, err := a.Srv().Store.Channel().GetSidebarCategories(userId, teamId)
|
||||
|
||||
if err != nil || len(categories.Categories) > 0 {
|
||||
// We've found something, so return
|
||||
return categories, err
|
||||
}
|
||||
}
|
||||
|
||||
mlog.Error("waitForSidebarCategories giving up", mlog.String("user_id", userId), mlog.String("team_id", teamId))
|
||||
|
||||
return &model.OrderedSidebarCategories{}, nil
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategoryOrder(userId, teamId string) ([]string, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategoryOrder(userId, teamId)
|
||||
}
|
||||
|
||||
func (a *App) GetSidebarCategory(categoryId string) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
return a.Srv().Store.Channel().GetSidebarCategory(categoryId)
|
||||
}
|
||||
|
||||
func (a *App) CreateSidebarCategory(userId, teamId string, newCategory *model.SidebarCategoryWithChannels) (*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
category, err := a.Srv().Store.Channel().CreateSidebarCategory(userId, teamId, newCategory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_CREATED, teamId, "", userId, nil)
|
||||
message.Add("category_id", category.Id)
|
||||
a.Publish(message)
|
||||
return category, nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategoryOrder(userId, teamId string, categoryOrder []string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().UpdateSidebarCategoryOrder(userId, teamId, categoryOrder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_ORDER_UPDATED, teamId, "", userId, nil)
|
||||
message.Add("order", categoryOrder)
|
||||
a.Publish(message)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) UpdateSidebarCategories(userId, teamId string, categories []*model.SidebarCategoryWithChannels) ([]*model.SidebarCategoryWithChannels, *model.AppError) {
|
||||
result, err := a.Srv().Store.Channel().UpdateSidebarCategories(userId, teamId, categories)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_UPDATED, teamId, "", userId, nil)
|
||||
a.Publish(message)
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *App) DeleteSidebarCategory(userId, teamId, categoryId string) *model.AppError {
|
||||
err := a.Srv().Store.Channel().DeleteSidebarCategory(categoryId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_SIDEBAR_CATEGORY_DELETED, teamId, "", userId, nil)
|
||||
message.Add("category_id", categoryId)
|
||||
a.Publish(message)
|
||||
|
||||
return nil
|
||||
}
|
||||
134
app/channel_category_test.go
Обычный файл
134
app/channel_category_test.go
Обычный файл
@@ -0,0 +1,134 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
)
|
||||
|
||||
func TestSidebarCategory(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
basicChannel2 := th.CreateChannel(th.BasicTeam)
|
||||
defer th.App.PermanentDeleteChannel(basicChannel2)
|
||||
user := th.CreateUser()
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
th.AddUserToChannel(user, basicChannel2)
|
||||
|
||||
var createdCategory *model.SidebarCategoryWithChannels
|
||||
t.Run("CreateSidebarCategory", func(t *testing.T) {
|
||||
catData := model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "TEST",
|
||||
},
|
||||
Channels: []string{th.BasicChannel.Id, basicChannel2.Id, basicChannel2.Id},
|
||||
}
|
||||
_, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
require.NotNil(t, err, "Should return error due to duplicate IDs")
|
||||
catData.Channels = []string{th.BasicChannel.Id, basicChannel2.Id}
|
||||
cat, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, cat, "Expected category object, got nil")
|
||||
createdCategory = cat
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) {
|
||||
require.NotNil(t, createdCategory)
|
||||
createdCategory.Channels = []string{th.BasicChannel.Id}
|
||||
updatedCat, err := th.App.UpdateSidebarCategories(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, updatedCat, "Expected category object, got nil")
|
||||
require.Len(t, updatedCat, 1)
|
||||
require.Len(t, updatedCat[0].Channels, 1)
|
||||
require.Equal(t, updatedCat[0].Channels[0], th.BasicChannel.Id)
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategoryOrder", func(t *testing.T) {
|
||||
err := th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
|
||||
require.NotNil(t, err, "Should return error due to invalid order")
|
||||
|
||||
actualOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Should fetch order successfully")
|
||||
|
||||
actualOrder[2], actualOrder[3] = actualOrder[3], actualOrder[2]
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.Nil(t, err, "Should update order successfully")
|
||||
|
||||
actualOrder[2] = "asd"
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.NotNil(t, err, "Should return error due to invalid id")
|
||||
})
|
||||
|
||||
t.Run("GetSidebarCategoryOrder", func(t *testing.T) {
|
||||
catOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.Len(t, catOrder, 4)
|
||||
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)
|
||||
})
|
||||
|
||||
t.Run("should return a store error if a db table is missing", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// Temporarily renaming a table to force a DB error.
|
||||
sqlSupplier := mainHelper.GetSQLSupplier()
|
||||
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||
require.Nil(t, err)
|
||||
}()
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "store.sql_channel.sidebar_categories.app_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
@@ -1898,124 +1898,3 @@ func TestClearChannelMembersCache(t *testing.T) {
|
||||
|
||||
th.App.ClearChannelMembersCache("channelID")
|
||||
}
|
||||
|
||||
func TestSidebarCategory(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
basicChannel2 := th.CreateChannel(th.BasicTeam)
|
||||
defer th.App.PermanentDeleteChannel(basicChannel2)
|
||||
user := th.CreateUser()
|
||||
defer th.App.Srv().Store.User().PermanentDelete(user.Id)
|
||||
th.LinkUserToTeam(user, th.BasicTeam)
|
||||
th.AddUserToChannel(user, basicChannel2)
|
||||
|
||||
var createdCategory *model.SidebarCategoryWithChannels
|
||||
t.Run("CreateSidebarCategory", func(t *testing.T) {
|
||||
catData := model.SidebarCategoryWithChannels{
|
||||
SidebarCategory: model.SidebarCategory{
|
||||
DisplayName: "TEST",
|
||||
},
|
||||
Channels: []string{th.BasicChannel.Id, basicChannel2.Id, basicChannel2.Id},
|
||||
}
|
||||
_, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
require.NotNil(t, err, "Should return error due to duplicate IDs")
|
||||
catData.Channels = []string{th.BasicChannel.Id, basicChannel2.Id}
|
||||
cat, err := th.App.CreateSidebarCategory(user.Id, th.BasicTeam.Id, &catData)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, cat, "Expected category object, got nil")
|
||||
createdCategory = cat
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategories", func(t *testing.T) {
|
||||
require.NotNil(t, createdCategory)
|
||||
createdCategory.Channels = []string{th.BasicChannel.Id}
|
||||
updatedCat, err := th.App.UpdateSidebarCategories(user.Id, th.BasicTeam.Id, []*model.SidebarCategoryWithChannels{createdCategory})
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.NotNil(t, updatedCat, "Expected category object, got nil")
|
||||
require.Len(t, updatedCat, 1)
|
||||
require.Len(t, updatedCat[0].Channels, 1)
|
||||
require.Equal(t, updatedCat[0].Channels[0], th.BasicChannel.Id)
|
||||
})
|
||||
|
||||
t.Run("UpdateSidebarCategoryOrder", func(t *testing.T) {
|
||||
err := th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, []string{th.BasicChannel.Id, basicChannel2.Id})
|
||||
require.NotNil(t, err, "Should return error due to invalid order")
|
||||
|
||||
actualOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Should fetch order successfully")
|
||||
|
||||
actualOrder[2], actualOrder[3] = actualOrder[3], actualOrder[2]
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.Nil(t, err, "Should update order successfully")
|
||||
|
||||
actualOrder[2] = "asd"
|
||||
err = th.App.UpdateSidebarCategoryOrder(user.Id, th.BasicTeam.Id, actualOrder)
|
||||
require.NotNil(t, err, "Should return error due to invalid id")
|
||||
})
|
||||
|
||||
t.Run("GetSidebarCategoryOrder", func(t *testing.T) {
|
||||
catOrder, err := th.App.GetSidebarCategoryOrder(user.Id, th.BasicTeam.Id)
|
||||
require.Nil(t, err, "Expected no error")
|
||||
require.Len(t, catOrder, 4)
|
||||
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)
|
||||
})
|
||||
|
||||
t.Run("should return a store error if a db table is missing", func(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// Temporarily renaming a table to force a DB error.
|
||||
sqlSupplier := mainHelper.GetSQLSupplier()
|
||||
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategories RENAME TO SidebarCategoriesTest")
|
||||
require.Nil(t, err)
|
||||
defer func() {
|
||||
_, err := sqlSupplier.GetMaster().Exec("ALTER TABLE SidebarCategoriesTest RENAME TO SidebarCategories")
|
||||
require.Nil(t, err)
|
||||
}()
|
||||
|
||||
categories, appErr := th.App.GetSidebarCategories(th.BasicUser.Id, th.BasicTeam.Id)
|
||||
assert.Nil(t, categories)
|
||||
assert.NotNil(t, appErr)
|
||||
assert.Equal(t, "store.sql_channel.sidebar_categories.app_error", appErr.Id)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user