Files
mostlymatter/app/shared_channel_notifier_test.go
Agniva De Sarker f0ecdcc5f5 Move Channels into App (#18623)
* 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
```
2021-10-12 11:39:49 +05:30

72 строки
2.4 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/mattermost/mattermost-server/v6/model"
)
func TestServerSyncSharedChannelHandler(t *testing.T) {
t.Run("sync service inactive, it does nothing", func(t *testing.T) {
th := SetupWithStoreMock(t)
defer th.TearDown()
mockService := NewMockSharedChannelService(nil)
mockService.active = false
th.App.ch.srv.SetSharedChannelSyncService(mockService)
th.App.ch.srv.SharedChannelSyncHandler(&model.WebSocketEvent{})
assert.Empty(t, mockService.channelNotifications)
})
t.Run("sync service active and broadcast envelope has ineligible event, it does nothing", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
mockService := NewMockSharedChannelService(nil)
mockService.active = true
th.App.ch.srv.SetSharedChannelSyncService(mockService)
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
websocketEvent := model.NewWebSocketEvent(model.WebsocketEventAddedToTeam, model.NewId(), channel.Id, "", nil)
th.App.ch.srv.SharedChannelSyncHandler(websocketEvent)
assert.Empty(t, mockService.channelNotifications)
})
t.Run("sync service active and broadcast envelope has eligible event but channel does not exist, it does nothing", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
mockService := NewMockSharedChannelService(nil)
mockService.active = true
th.App.ch.srv.SetSharedChannelSyncService(mockService)
websocketEvent := model.NewWebSocketEvent(model.WebsocketEventPosted, model.NewId(), model.NewId(), "", nil)
th.App.ch.srv.SharedChannelSyncHandler(websocketEvent)
assert.Empty(t, mockService.channelNotifications)
})
t.Run("sync service active when received eligible event, it triggers a shared channel content sync", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
mockService := NewMockSharedChannelService(nil)
mockService.active = true
th.App.ch.srv.SetSharedChannelSyncService(mockService)
channel := th.CreateChannel(th.BasicTeam, WithShared(true))
websocketEvent := model.NewWebSocketEvent(model.WebsocketEventPosted, model.NewId(), channel.Id, "", nil)
th.App.ch.srv.SharedChannelSyncHandler(websocketEvent)
assert.Len(t, mockService.channelNotifications, 1)
assert.Equal(t, channel.Id, mockService.channelNotifications[0])
})
}