2022-04-25 20:58:08 +02:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
// See LICENSE.txt for license information.
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
package boards
|
2021-09-16 21:31:02 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
"github.com/golang/mock/gomock"
|
2022-04-20 17:01:40 +02:00
|
|
|
"github.com/mattermost/focalboard/server/integrationtests"
|
2021-09-16 21:31:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2022-04-19 17:18:31 +02:00
|
|
|
"github.com/mattermost/focalboard/server/server"
|
2021-09-16 21:31:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/ws"
|
2022-04-20 17:01:40 +02:00
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
mockservicesapi "github.com/mattermost/focalboard/server/model/mocks"
|
|
|
|
|
2021-11-09 16:56:04 +02:00
|
|
|
serverModel "github.com/mattermost/mattermost-server/v6/model"
|
2022-07-18 19:21:57 +02:00
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2021-11-09 16:56:04 +02:00
|
|
|
|
2021-09-16 21:31:02 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-04-20 17:01:40 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-16 21:31:02 +02:00
|
|
|
)
|
|
|
|
|
2022-04-19 17:18:31 +02:00
|
|
|
type TestHelper struct {
|
|
|
|
Server *server.Server
|
|
|
|
}
|
|
|
|
|
2022-04-20 17:01:40 +02:00
|
|
|
func SetupTestHelper(t *testing.T) (*TestHelper, func()) {
|
2022-04-19 17:18:31 +02:00
|
|
|
th := &TestHelper{}
|
|
|
|
th.Server = newTestServer()
|
|
|
|
|
2022-04-20 17:01:40 +02:00
|
|
|
err := th.Server.Start()
|
|
|
|
require.NoError(t, err, "Server start should not error")
|
|
|
|
|
|
|
|
tearDown := func() {
|
|
|
|
err := th.Server.Shutdown()
|
|
|
|
require.NoError(t, err, "Server shutdown should not error")
|
2022-04-19 17:18:31 +02:00
|
|
|
}
|
2022-04-20 17:01:40 +02:00
|
|
|
return th, tearDown
|
|
|
|
}
|
2022-04-19 17:18:31 +02:00
|
|
|
|
2022-04-20 17:01:40 +02:00
|
|
|
func newTestServer() *server.Server {
|
|
|
|
return integrationtests.NewTestServerPluginMode()
|
2022-04-19 17:18:31 +02:00
|
|
|
}
|
2021-11-09 16:56:04 +02:00
|
|
|
func TestConfigurationNullConfiguration(t *testing.T) {
|
2022-07-18 19:21:57 +02:00
|
|
|
boardsApp := &BoardsApp{}
|
|
|
|
assert.NotNil(t, boardsApp.getConfiguration())
|
2021-09-16 21:31:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOnConfigurationChange(t *testing.T) {
|
2021-11-09 16:56:04 +02:00
|
|
|
stringRef := ""
|
2021-09-16 21:31:02 +02:00
|
|
|
|
2021-11-09 16:56:04 +02:00
|
|
|
basePlugins := make(map[string]map[string]interface{})
|
2022-07-18 19:21:57 +02:00
|
|
|
basePlugins[PluginName] = make(map[string]interface{})
|
|
|
|
basePlugins[PluginName][SharedBoardsName] = true
|
2021-09-16 21:31:02 +02:00
|
|
|
|
2021-11-09 16:56:04 +02:00
|
|
|
baseFeatureFlags := &serverModel.FeatureFlags{
|
|
|
|
BoardsFeatureFlags: "Feature1-Feature2",
|
|
|
|
}
|
|
|
|
basePluginSettings := &serverModel.PluginSettings{
|
|
|
|
Directory: &stringRef,
|
|
|
|
Plugins: basePlugins,
|
|
|
|
}
|
2022-04-25 20:58:08 +02:00
|
|
|
intRef := 365
|
|
|
|
baseDataRetentionSettings := &serverModel.DataRetentionSettings{
|
|
|
|
BoardsRetentionDays: &intRef,
|
|
|
|
}
|
2022-07-08 16:43:43 +02:00
|
|
|
usernameRef := "username"
|
|
|
|
baseTeamSettings := &serverModel.TeamSettings{
|
|
|
|
TeammateNameDisplay: &usernameRef,
|
|
|
|
}
|
2021-11-09 16:56:04 +02:00
|
|
|
|
2022-11-02 22:07:10 +02:00
|
|
|
falseRef := false
|
|
|
|
basePrivacySettings := &serverModel.PrivacySettings{
|
|
|
|
ShowEmailAddress: &falseRef,
|
|
|
|
ShowFullName: &falseRef,
|
|
|
|
}
|
|
|
|
|
2021-11-09 16:56:04 +02:00
|
|
|
baseConfig := &serverModel.Config{
|
2022-04-25 20:58:08 +02:00
|
|
|
FeatureFlags: baseFeatureFlags,
|
|
|
|
PluginSettings: *basePluginSettings,
|
|
|
|
DataRetentionSettings: *baseDataRetentionSettings,
|
2022-07-08 16:43:43 +02:00
|
|
|
TeamSettings: *baseTeamSettings,
|
2022-11-02 22:07:10 +02:00
|
|
|
PrivacySettings: *basePrivacySettings,
|
2021-11-09 16:56:04 +02:00
|
|
|
}
|
2021-09-16 21:31:02 +02:00
|
|
|
|
|
|
|
t.Run("Test Load Plugin Success", func(t *testing.T) {
|
2022-04-20 17:01:40 +02:00
|
|
|
th, tearDown := SetupTestHelper(t)
|
|
|
|
defer tearDown()
|
2021-09-16 21:31:02 +02:00
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
api := mockservicesapi.NewMockServicesAPI(ctrl)
|
|
|
|
api.EXPECT().GetConfig().Return(baseConfig)
|
|
|
|
|
|
|
|
b := &BoardsApp{
|
|
|
|
server: th.Server,
|
|
|
|
wsPluginAdapter: &FakePluginAdapter{},
|
|
|
|
servicesAPI: api,
|
|
|
|
logger: mlog.CreateConsoleTestLogger(true, mlog.LvlError),
|
|
|
|
}
|
2021-09-16 21:31:02 +02:00
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
err := b.OnConfigurationChange()
|
2021-11-09 16:56:04 +02:00
|
|
|
assert.NoError(t, err)
|
2021-09-16 21:31:02 +02:00
|
|
|
assert.Equal(t, 1, count)
|
2021-11-09 16:56:04 +02:00
|
|
|
|
|
|
|
// make sure both App and Server got updated
|
2022-07-18 19:21:57 +02:00
|
|
|
assert.True(t, b.server.Config().EnablePublicSharedBoards)
|
|
|
|
assert.True(t, b.server.App().GetClientConfig().EnablePublicSharedBoards)
|
2021-11-09 16:56:04 +02:00
|
|
|
|
2022-07-18 19:21:57 +02:00
|
|
|
assert.Equal(t, "true", b.server.Config().FeatureFlags["Feature1"])
|
|
|
|
assert.Equal(t, "true", b.server.Config().FeatureFlags["Feature2"])
|
|
|
|
assert.Equal(t, "", b.server.Config().FeatureFlags["Feature3"])
|
2021-09-16 21:31:02 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
var count = 0
|
|
|
|
|
|
|
|
type FakePluginAdapter struct {
|
|
|
|
ws.PluginAdapter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *FakePluginAdapter) BroadcastConfigChange(clientConfig model.ClientConfig) {
|
|
|
|
count++
|
|
|
|
}
|