MM-37576: Fix reference to incorrect error variable (#18066)
We use the correct error variable returned from the store method prior to it. https://mattermost.atlassian.net/browse/MM-37576 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7c22202330
Коммит
e49f385598
@@ -2275,7 +2275,7 @@ func (a *App) UpdateThreadReadForUser(userID, teamID, threadID string, timestamp
|
|||||||
}
|
}
|
||||||
membership, storeErr := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts)
|
membership, storeErr := a.Srv().Store.Thread().MaintainMembership(userID, threadID, opts)
|
||||||
if storeErr != nil {
|
if storeErr != nil {
|
||||||
return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, model.NewAppError("UpdateThreadReadForUser", "app.user.update_thread_read_for_user.app_error", nil, storeErr.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
post, err := a.GetSinglePost(threadID)
|
post, err := a.GetSinglePost(threadID)
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ import (
|
|||||||
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
"github.com/mattermost/mattermost-server/v6/einterfaces/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v6/model"
|
"github.com/mattermost/mattermost-server/v6/model"
|
||||||
oauthgitlab "github.com/mattermost/mattermost-server/v6/model/gitlab"
|
oauthgitlab "github.com/mattermost/mattermost-server/v6/model/gitlab"
|
||||||
|
"github.com/mattermost/mattermost-server/v6/services/users"
|
||||||
"github.com/mattermost/mattermost-server/v6/store"
|
"github.com/mattermost/mattermost-server/v6/store"
|
||||||
|
storemocks "github.com/mattermost/mattermost-server/v6/store/storetest/mocks"
|
||||||
"github.com/mattermost/mattermost-server/v6/utils/testutils"
|
"github.com/mattermost/mattermost-server/v6/utils/testutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1508,14 +1510,15 @@ func TestPatchUser(t *testing.T) {
|
|||||||
func TestUpdateThreadReadForUser(t *testing.T) {
|
func TestUpdateThreadReadForUser(t *testing.T) {
|
||||||
os.Setenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS", "true")
|
os.Setenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS", "true")
|
||||||
defer os.Unsetenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS")
|
defer os.Unsetenv("MM_FEATUREFLAGS_COLLAPSEDTHREADS")
|
||||||
th := Setup(t).InitBasic()
|
|
||||||
defer th.TearDown()
|
|
||||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
||||||
*cfg.ServiceSettings.ThreadAutoFollow = true
|
|
||||||
*cfg.ServiceSettings.CollapsedThreads = model.CollapsedThreadsDefaultOn
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("Ensure thread membership is created and followed", func(t *testing.T) {
|
t.Run("Ensure thread membership is created and followed", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||||
|
*cfg.ServiceSettings.ThreadAutoFollow = true
|
||||||
|
*cfg.ServiceSettings.CollapsedThreads = model.CollapsedThreadsDefaultOn
|
||||||
|
})
|
||||||
|
|
||||||
rootPost, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: th.BasicUser2.Id, CreateAt: model.GetMillis(), ChannelId: th.BasicChannel.Id, Message: "hi"}, th.BasicChannel, false, false)
|
rootPost, appErr := th.App.CreatePost(th.Context, &model.Post{UserId: th.BasicUser2.Id, CreateAt: model.GetMillis(), ChannelId: th.BasicChannel.Id, Message: "hi"}, th.BasicChannel, false, false)
|
||||||
require.Nil(t, appErr)
|
require.Nil(t, appErr)
|
||||||
replyPost, appErr := th.App.CreatePost(th.Context, &model.Post{RootId: rootPost.Id, UserId: th.BasicUser2.Id, CreateAt: model.GetMillis(), ChannelId: th.BasicChannel.Id, Message: "hi"}, th.BasicChannel, false, false)
|
replyPost, appErr := th.App.CreatePost(th.Context, &model.Post{RootId: rootPost.Id, UserId: th.BasicUser2.Id, CreateAt: model.GetMillis(), ChannelId: th.BasicChannel.Id, Message: "hi"}, th.BasicChannel, false, false)
|
||||||
@@ -1536,6 +1539,34 @@ func TestUpdateThreadReadForUser(t *testing.T) {
|
|||||||
require.NotNil(t, threadMembership)
|
require.NotNil(t, threadMembership)
|
||||||
assert.True(t, threadMembership.Following)
|
assert.True(t, threadMembership.Following)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("Ensure no panic on error", func(t *testing.T) {
|
||||||
|
th := SetupWithStoreMock(t)
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
mockStore := th.App.Srv().Store.(*storemocks.Store)
|
||||||
|
mockUserStore := storemocks.UserStore{}
|
||||||
|
mockUserStore.On("Count", mock.Anything).Return(int64(10), nil)
|
||||||
|
mockUserStore.On("Get", mock.Anything, "user1").Return(&model.User{Id: "user1"}, nil)
|
||||||
|
|
||||||
|
mockThreadStore := storemocks.ThreadStore{}
|
||||||
|
mockThreadStore.On("MaintainMembership", "user1", "postid", mock.Anything).Return(nil, errors.New("error"))
|
||||||
|
|
||||||
|
var err error
|
||||||
|
th.App.srv.userService, err = users.New(users.ServiceConfig{
|
||||||
|
UserStore: &mockUserStore,
|
||||||
|
SessionStore: &storemocks.SessionStore{},
|
||||||
|
OAuthStore: &storemocks.OAuthStore{},
|
||||||
|
ConfigFn: th.App.srv.Config,
|
||||||
|
LicenseFn: th.App.srv.License,
|
||||||
|
})
|
||||||
|
require.NoError(t, err)
|
||||||
|
mockStore.On("User").Return(&mockUserStore)
|
||||||
|
mockStore.On("Thread").Return(&mockThreadStore)
|
||||||
|
|
||||||
|
_, err = th.App.UpdateThreadReadForUser("user1", "team1", "postid", 100)
|
||||||
|
require.Error(t, err)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateUserWithInitialPreferences(t *testing.T) {
|
func TestCreateUserWithInitialPreferences(t *testing.T) {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user