* Move Channels into App In this PR, we make Channels as part of App instead of Server. This is part of the transition period of moving fields from Server to Channels. For now, Channels contains Server. So the hierarchy is App -> Channels -> Server. And as a first step, we also move httpService to Channels. ```release-note NONE ``` * Fixing another test ```release-note NONE ``` * new method ```release-note NONE ```
87 строки
2.8 KiB
Go
87 строки
2.8 KiB
Go
// 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/v6/model"
|
|
"github.com/mattermost/mattermost-server/v6/testlib"
|
|
)
|
|
|
|
func TestSharedChannelSyncForReactionActions(t *testing.T) {
|
|
t.Run("adding a reaction in a shared channel performs a content sync when sync service is running on that node", func(t *testing.T) {
|
|
th := Setup(t).InitBasic()
|
|
|
|
sharedChannelService := NewMockSharedChannelService(nil)
|
|
th.App.ch.srv.sharedChannelService = sharedChannelService
|
|
testCluster := &testlib.FakeClusterInterface{}
|
|
th.Server.Cluster = testCluster
|
|
|
|
user := th.BasicUser
|
|
|
|
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
|
|
|
post, err := th.App.CreatePost(th.Context, &model.Post{
|
|
UserId: user.Id,
|
|
ChannelId: channel.Id,
|
|
Message: "Hello folks",
|
|
}, channel, false, true)
|
|
require.Nil(t, err, "Creating a post should not error")
|
|
|
|
reaction := &model.Reaction{
|
|
UserId: user.Id,
|
|
PostId: post.Id,
|
|
EmojiName: "+1",
|
|
}
|
|
|
|
_, err = th.App.SaveReactionForPost(th.Context, reaction)
|
|
require.Nil(t, err, "Adding a reaction should not error")
|
|
|
|
th.TearDown() // We need to enforce teardown because reaction instrumentation happens in a goroutine
|
|
|
|
assert.Len(t, sharedChannelService.channelNotifications, 2)
|
|
assert.Equal(t, channel.Id, sharedChannelService.channelNotifications[0])
|
|
assert.Equal(t, channel.Id, sharedChannelService.channelNotifications[1])
|
|
})
|
|
|
|
t.Run("removing a reaction in a shared channel performs a content sync when sync service is running on that node", func(t *testing.T) {
|
|
th := Setup(t).InitBasic()
|
|
|
|
sharedChannelService := NewMockSharedChannelService(nil)
|
|
th.App.ch.srv.sharedChannelService = sharedChannelService
|
|
testCluster := &testlib.FakeClusterInterface{}
|
|
th.Server.Cluster = testCluster
|
|
|
|
user := th.BasicUser
|
|
|
|
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
|
|
|
|
post, err := th.App.CreatePost(th.Context, &model.Post{
|
|
UserId: user.Id,
|
|
ChannelId: channel.Id,
|
|
Message: "Hello folks",
|
|
}, channel, false, true)
|
|
require.Nil(t, err, "Creating a post should not error")
|
|
|
|
reaction := &model.Reaction{
|
|
UserId: user.Id,
|
|
PostId: post.Id,
|
|
EmojiName: "+1",
|
|
}
|
|
|
|
err = th.App.DeleteReactionForPost(th.Context, reaction)
|
|
require.Nil(t, err, "Adding a reaction should not error")
|
|
|
|
th.TearDown() // We need to enforce teardown because reaction instrumentation happens in a goroutine
|
|
|
|
assert.Len(t, sharedChannelService.channelNotifications, 2)
|
|
assert.Equal(t, channel.Id, sharedChannelService.channelNotifications[0])
|
|
assert.Equal(t, channel.Id, sharedChannelService.channelNotifications[1])
|
|
})
|
|
}
|