snapshot of https://github.com/mattermost/mattermost.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
Some checks failed
Server CI / Postgres (shard 0) (push) Has been skipped
Server CI / Postgres (shard 3) (push) Has been skipped
BuildEnv Docker Image / build-image (push) Failing after 4s
BuildEnv Docker Image / build-image-fips (push) Failing after 4s
Migration Review & Release Notes / Generate migration review & release notes (push) Failing after 3s
Server CI / Build Environment (push) Failing after 3s
Server CI / Postgres (shard 1) (push) Has been skipped
Tools CI / check-style (mattermost-govet) (push) Failing after 4s
Server CI / Postgres (shard 2) (push) Has been skipped
Tools CI / check-style (mmgotool) (push) Failing after 3s
Server CI / Elasticsearch v8 Compatibility (push) Has been skipped
Server CI / OpenSearch v2 Compatibility (push) Has been skipped
Server CI / Postgres FIPS (shard 0) (push) Has been skipped
Tools CI / Test (mattermost-govet) (push) Failing after 3s
Server CI / Postgres FIPS (shard 1) (push) Has been skipped
Server CI / Postgres FIPS (shard 2) (push) Has been skipped
Tools CI / Test (mmgotool) (push) Failing after 3s
Server CI / Postgres FIPS (shard 3) (push) Has been skipped
Server CI / Run mmctl tests (push) Has been skipped
Server CI / Run mmctl tests (FIPS) (push) Has been skipped
Server CI / Merge Postgres Test Results (push) Has been skipped
Server CI / Merge Postgres FIPS Test Results (push) Has been skipped
Server CI / Check backport migrations (push) Has been skipped
Server CI / Check generated files (push) Has been skipped
Server CI / check-style (push) Has been skipped
Server CI / Vet API (push) Has been skipped
Server CI / Build mattermost server app (push) Has been skipped
Server CI / Server CI Complete (push) Failing after 2s
Server CI / Server CI Artifacts (push) Has been skipped
Server CI / Sentry Upload (push) Has been skipped
Server CI / Server CI Report (push) Failing after 5m1s
Server CI Nightly Race / Race Detector (push) Has been skipped
CodeQL / Analyze (go) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Webapp CI Cache Warm / Warm Webapp node_modules Cache (push) Has been cancelled
E2E CI Cache Warm / Warm E2E npm Registry Cache (push) Has been cancelled
API / build (push) Has been cancelled
Web App CI / check-types (push) Has been cancelled
Web App CI / check-lint (push) Has been cancelled
Web App CI / check-i18n (push) Has been cancelled
Web App CI / check-external-links (push) Has been cancelled
Web App CI / test (platform) (push) Has been cancelled
Web App CI / test (mattermost-redux) (push) Has been cancelled
Web App CI / test (channels shard 1/4) (push) Has been cancelled
Web App CI / test (channels shard 2/4) (push) Has been cancelled
Web App CI / test (channels shard 3/4) (push) Has been cancelled
Web App CI / test (channels shard 4/4) (push) Has been cancelled
Web App CI / upload-coverage (push) Has been cancelled
Web App CI / build (push) Has been cancelled
YAML Lint / yamllint (push) Has been cancelled
Push mirrored docker images / cd/Push mirrored docker images (push) Has been cancelled
docs-cd / Build and deploy docs (push) Has been cancelled
Docs CI / build (push) Has been cancelled
E2E Cache Warm: Cypress deps / Warm Cypress deps cache (push) Has been cancelled
Scorecards supply-chain security / Scorecard analysis (push) Has been cancelled
Server CI Weekly / Postgres FIPS (push) Has been skipped
Server CI Weekly / Run mmctl tests (FIPS) (push) Has been skipped
Server CI Weekly / Postgres with binary parameters (push) Has been skipped
Server CI Weekly / Build Environment (push) Failing after 1s
Server CI Cache Warm / Warm Go Module and Build Cache (push) Failing after 2s
Server CI Nightly Race / Build Environment (push) Failing after 1s
This commit is contained in:
324
server/platform/services/sharedchannel/service_api_test.go
Normal file
324
server/platform/services/sharedchannel/service_api_test.go
Normal file
@@ -0,0 +1,324 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package sharedchannel
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/i18n"
|
||||
"github.com/mattermost/mattermost/server/public/shared/mlog"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store/storetest/mocks"
|
||||
)
|
||||
|
||||
// testNoopPlatform satisfies PlatformIface for API tests that trigger websocket/cache notifications.
|
||||
type testNoopPlatform struct{}
|
||||
|
||||
func (testNoopPlatform) InvalidateCacheForUser(userID string) {}
|
||||
|
||||
func (testNoopPlatform) InvalidateCacheForChannel(channel *model.Channel) {}
|
||||
|
||||
func TestUnshareChannel_systemPostsForEachRemoteWorkspace(t *testing.T) {
|
||||
channelID := model.NewId()
|
||||
teamID := model.NewId()
|
||||
channel := &model.Channel{Id: channelID, TeamId: teamID, Name: "town-square", DisplayName: "Town Square"}
|
||||
|
||||
remoteIDA := model.NewId()
|
||||
remoteIDB := model.NewId()
|
||||
remotes := []*model.SharedChannelRemote{
|
||||
{Id: model.NewId(), ChannelId: channelID, RemoteId: remoteIDA, DeleteAt: 0},
|
||||
{Id: model.NewId(), ChannelId: channelID, RemoteId: remoteIDB, DeleteAt: 0},
|
||||
}
|
||||
rcA := &model.RemoteCluster{RemoteId: remoteIDA, DisplayName: "Workspace A"}
|
||||
rcB := &model.RemoteCluster{RemoteId: remoteIDB, Name: "internal-b"}
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockSharedChannelStore := mocks.SharedChannelStore{}
|
||||
mockRemoteClusterStore := mocks.RemoteClusterStore{}
|
||||
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("SharedChannel").Return(&mockSharedChannelStore)
|
||||
mockStore.On("RemoteCluster").Return(&mockRemoteClusterStore)
|
||||
|
||||
mockChannelStore.On("Get", channelID, true).Return(channel, nil).Once()
|
||||
mockChannelStore.On("Get", channelID, false).Return(channel, nil).Once()
|
||||
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 10000, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return(remotes, nil).Once()
|
||||
mockSharedChannelStore.On("Delete", channelID).Return(true, nil).Once()
|
||||
|
||||
mockRemoteClusterStore.On("Get", remoteIDA, false).Return(rcA, nil).Once()
|
||||
mockRemoteClusterStore.On("Get", remoteIDB, false).Return(rcB, nil).Once()
|
||||
|
||||
mockApp := &MockAppIface{}
|
||||
bot := &model.Bot{UserId: model.NewId()}
|
||||
var postedWorkspaces []string
|
||||
mockApp.On("GetSystemBot", mock.Anything).Return(bot, (*model.AppError)(nil))
|
||||
mockApp.On("Publish", mock.Anything).Return()
|
||||
mockApp.On("CreatePost", mock.Anything, mock.AnythingOfType("*model.Post"), mock.AnythingOfType("*model.Channel"), mock.Anything).
|
||||
Run(func(args mock.Arguments) {
|
||||
post := args.Get(1).(*model.Post)
|
||||
wn, _ := post.GetProps()[model.PostPropsSharedChannelWorkspaceName].(string)
|
||||
assert.Equal(t, model.SharedChannelStatePostValueUnshared, post.GetProps()[model.PostPropsSharedChannelState])
|
||||
postedWorkspaces = append(postedWorkspaces, wn)
|
||||
assert.Equal(t,
|
||||
i18n.T("shared_channel.system_message.no_longer_shared", map[string]any{"WorkspaceName": wn}),
|
||||
post.Message,
|
||||
)
|
||||
}).Return(&model.Post{}, false, (*model.AppError)(nil))
|
||||
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
platform: testNoopPlatform{},
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
deleted, err := scs.UnshareChannel(channelID)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, deleted)
|
||||
|
||||
mockApp.AssertNumberOfCalls(t, "CreatePost", 2)
|
||||
assert.ElementsMatch(t, []string{"Workspace A", "internal-b"}, postedWorkspaces)
|
||||
mockApp.AssertExpectations(t)
|
||||
mockSharedChannelStore.AssertExpectations(t)
|
||||
mockRemoteClusterStore.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestUnshareChannel_whenListRemotesFails_stillUnsharesWithoutSystemPosts(t *testing.T) {
|
||||
channelID := model.NewId()
|
||||
channel := &model.Channel{Id: channelID, TeamId: model.NewId()}
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockSharedChannelStore := mocks.SharedChannelStore{}
|
||||
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("SharedChannel").Return(&mockSharedChannelStore)
|
||||
|
||||
mockChannelStore.On("Get", channelID, true).Return(channel, nil).Once()
|
||||
mockChannelStore.On("Get", channelID, false).Return(channel, nil).Once()
|
||||
|
||||
listErr := errors.New("store remotes unavailable")
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 10000, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return(([]*model.SharedChannelRemote)(nil), listErr).Once()
|
||||
mockSharedChannelStore.On("Delete", channelID).Return(true, nil).Once()
|
||||
|
||||
mockApp := &MockAppIface{}
|
||||
mockApp.On("Publish", mock.Anything).Return()
|
||||
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
platform: testNoopPlatform{},
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
deleted, err := scs.UnshareChannel(channelID)
|
||||
require.NoError(t, err)
|
||||
assert.True(t, deleted)
|
||||
|
||||
mockApp.AssertNotCalled(t, "CreatePost")
|
||||
mockApp.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestUnshareChannel_whenRemoteClusterMissingUsesRemoteIdInPost(t *testing.T) {
|
||||
channelID := model.NewId()
|
||||
channel := &model.Channel{Id: channelID, TeamId: model.NewId()}
|
||||
remoteID := model.NewId()
|
||||
remotes := []*model.SharedChannelRemote{
|
||||
{Id: model.NewId(), ChannelId: channelID, RemoteId: remoteID, DeleteAt: 0},
|
||||
}
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockSharedChannelStore := mocks.SharedChannelStore{}
|
||||
mockRemoteClusterStore := mocks.RemoteClusterStore{}
|
||||
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("SharedChannel").Return(&mockSharedChannelStore)
|
||||
mockStore.On("RemoteCluster").Return(&mockRemoteClusterStore)
|
||||
|
||||
mockChannelStore.On("Get", channelID, true).Return(channel, nil).Once()
|
||||
mockChannelStore.On("Get", channelID, false).Return(channel, nil).Once()
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 10000, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return(remotes, nil).Once()
|
||||
mockSharedChannelStore.On("Delete", channelID).Return(true, nil).Once()
|
||||
mockRemoteClusterStore.On("Get", remoteID, false).Return((*model.RemoteCluster)(nil), errors.New("not found")).Once()
|
||||
|
||||
mockApp := &MockAppIface{}
|
||||
bot := &model.Bot{UserId: model.NewId()}
|
||||
mockApp.On("GetSystemBot", mock.Anything).Return(bot, (*model.AppError)(nil))
|
||||
mockApp.On("Publish", mock.Anything).Return()
|
||||
mockApp.On("CreatePost", mock.Anything, mock.AnythingOfType("*model.Post"), mock.AnythingOfType("*model.Channel"), mock.Anything).
|
||||
Run(func(args mock.Arguments) {
|
||||
post := args.Get(1).(*model.Post)
|
||||
assert.Equal(t, remoteID, post.GetProps()[model.PostPropsSharedChannelWorkspaceName])
|
||||
}).Return(&model.Post{}, false, (*model.AppError)(nil))
|
||||
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
platform: testNoopPlatform{},
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
_, err := scs.UnshareChannel(channelID)
|
||||
require.NoError(t, err)
|
||||
mockApp.AssertNumberOfCalls(t, "CreatePost", 1)
|
||||
}
|
||||
|
||||
func TestUninviteRemoteFromChannel_postsUnsharedSystemMessage(t *testing.T) {
|
||||
channelID := model.NewId()
|
||||
remoteID := model.NewId()
|
||||
scrID := model.NewId()
|
||||
channel := &model.Channel{Id: channelID, TeamId: model.NewId()}
|
||||
scr := &model.SharedChannelRemote{
|
||||
Id: scrID,
|
||||
ChannelId: channelID,
|
||||
RemoteId: remoteID,
|
||||
DeleteAt: 0,
|
||||
}
|
||||
rc := &model.RemoteCluster{RemoteId: remoteID, DisplayName: "Peer workspace"}
|
||||
remaining := []*model.SharedChannelRemote{{Id: model.NewId(), ChannelId: channelID, RemoteId: model.NewId(), DeleteAt: 0}}
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
setupMockServerWithConfig(mockServer)
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockSharedChannelStore := mocks.SharedChannelStore{}
|
||||
mockRemoteClusterStore := mocks.RemoteClusterStore{}
|
||||
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("SharedChannel").Return(&mockSharedChannelStore)
|
||||
mockStore.On("RemoteCluster").Return(&mockRemoteClusterStore)
|
||||
|
||||
mockSharedChannelStore.On("GetRemoteByIds", channelID, remoteID).Return(scr, nil).Once()
|
||||
mockSharedChannelStore.On("DeleteRemote", scrID).Return(true, nil).Once()
|
||||
mockChannelStore.On("Get", channelID, true).Return(channel, nil).Once()
|
||||
mockRemoteClusterStore.On("Get", remoteID, false).Return(rc, nil).Once()
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 1, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return(remaining, nil).Once()
|
||||
|
||||
mockApp := &MockAppIface{}
|
||||
bot := &model.Bot{UserId: model.NewId()}
|
||||
mockApp.On("GetSystemBot", mock.Anything).Return(bot, (*model.AppError)(nil))
|
||||
mockApp.On("CreatePost", mock.Anything, mock.AnythingOfType("*model.Post"), mock.AnythingOfType("*model.Channel"), mock.Anything).
|
||||
Run(func(args mock.Arguments) {
|
||||
post := args.Get(1).(*model.Post)
|
||||
assert.Equal(t, "Peer workspace", post.GetProps()[model.PostPropsSharedChannelWorkspaceName])
|
||||
assert.Equal(t, model.SharedChannelStatePostValueUnshared, post.GetProps()[model.PostPropsSharedChannelState])
|
||||
}).Return(&model.Post{}, false, (*model.AppError)(nil))
|
||||
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
platform: testNoopPlatform{},
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
err := scs.UninviteRemoteFromChannel(channelID, remoteID)
|
||||
require.NoError(t, err)
|
||||
|
||||
mockApp.AssertNumberOfCalls(t, "CreatePost", 1)
|
||||
mockSharedChannelStore.AssertNotCalled(t, "Delete", mock.Anything)
|
||||
mockApp.AssertExpectations(t)
|
||||
mockRemoteClusterStore.AssertExpectations(t)
|
||||
}
|
||||
|
||||
func TestUninviteRemoteFromChannel_whenLastRemoteUnsharesChannel(t *testing.T) {
|
||||
channelID := model.NewId()
|
||||
remoteID := model.NewId()
|
||||
scrID := model.NewId()
|
||||
channel := &model.Channel{Id: channelID, TeamId: model.NewId()}
|
||||
scr := &model.SharedChannelRemote{
|
||||
Id: scrID,
|
||||
ChannelId: channelID,
|
||||
RemoteId: remoteID,
|
||||
DeleteAt: 0,
|
||||
}
|
||||
rc := &model.RemoteCluster{RemoteId: remoteID, DisplayName: "Last peer"}
|
||||
|
||||
mockServer := &MockServerIface{}
|
||||
logger := mlog.CreateConsoleTestLogger(t)
|
||||
mockServer.On("Log").Return(logger)
|
||||
setupMockServerWithConfig(mockServer)
|
||||
|
||||
mockStore := &mocks.Store{}
|
||||
mockChannelStore := mocks.ChannelStore{}
|
||||
mockSharedChannelStore := mocks.SharedChannelStore{}
|
||||
mockRemoteClusterStore := mocks.RemoteClusterStore{}
|
||||
|
||||
mockServer.On("GetStore").Return(mockStore)
|
||||
mockStore.On("Channel").Return(&mockChannelStore)
|
||||
mockStore.On("SharedChannel").Return(&mockSharedChannelStore)
|
||||
mockStore.On("RemoteCluster").Return(&mockRemoteClusterStore)
|
||||
|
||||
mockSharedChannelStore.On("GetRemoteByIds", channelID, remoteID).Return(scr, nil).Once()
|
||||
mockSharedChannelStore.On("DeleteRemote", scrID).Return(true, nil).Once()
|
||||
// Channel load for uninvite system post, then UnshareChannel initial get, then UnshareChannel post-delete get.
|
||||
mockChannelStore.On("Get", channelID, true).Return(channel, nil).Times(2)
|
||||
mockChannelStore.On("Get", channelID, false).Return(channel, nil).Once()
|
||||
mockRemoteClusterStore.On("Get", remoteID, false).Return(rc, nil).Once()
|
||||
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 1, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return([]*model.SharedChannelRemote{}, nil).Once()
|
||||
mockSharedChannelStore.On("GetRemotes", 0, 10000, model.SharedChannelRemoteFilterOpts{
|
||||
ChannelId: channelID,
|
||||
IncludeUnconfirmed: true,
|
||||
}).Return([]*model.SharedChannelRemote{}, nil).Once()
|
||||
mockSharedChannelStore.On("Delete", channelID).Return(true, nil).Once()
|
||||
|
||||
mockApp := &MockAppIface{}
|
||||
bot := &model.Bot{UserId: model.NewId()}
|
||||
mockApp.On("GetSystemBot", mock.Anything).Return(bot, (*model.AppError)(nil))
|
||||
mockApp.On("Publish", mock.Anything).Return()
|
||||
mockApp.On("CreatePost", mock.Anything, mock.AnythingOfType("*model.Post"), mock.AnythingOfType("*model.Channel"), mock.Anything).
|
||||
Return(&model.Post{}, false, (*model.AppError)(nil))
|
||||
|
||||
scs := &Service{
|
||||
server: mockServer,
|
||||
platform: testNoopPlatform{},
|
||||
app: mockApp,
|
||||
}
|
||||
|
||||
err := scs.UninviteRemoteFromChannel(channelID, remoteID)
|
||||
require.NoError(t, err)
|
||||
|
||||
// One system post from UninviteRemoteFromChannel; UnshareChannel sees no remotes so it does not add more.
|
||||
mockApp.AssertNumberOfCalls(t, "CreatePost", 1)
|
||||
mockSharedChannelStore.AssertCalled(t, "Delete", channelID)
|
||||
mockRemoteClusterStore.AssertExpectations(t)
|
||||
}
|
||||
Reference in New Issue
Block a user