diff --git a/plugin/helpers_config.go b/plugin/helpers_config.go index 613b03473d..512fbbd723 100644 --- a/plugin/helpers_config.go +++ b/plugin/helpers_config.go @@ -18,7 +18,7 @@ func (p *HelpersImpl) CheckRequiredServerConfiguration(req *model.Config) (bool, cfg := p.API.GetConfig() - mc, err := utils.Merge(req, cfg, nil) + mc, err := utils.Merge(cfg, req, nil) if err != nil { return false, errors.Wrap(err, "could not merge configurations") } diff --git a/plugin/helpers_config_test.go b/plugin/helpers_config_test.go index 82838241a2..79357e37ec 100644 --- a/plugin/helpers_config_test.go +++ b/plugin/helpers_config_test.go @@ -27,12 +27,15 @@ func TestCheckRequiredServerConfiguration(t *testing.T) { ShouldReturn: true, ShouldError: false, }, - "same configurations": { + "contains required configuration": { SetupAPI: func(api *plugintest.API) *plugintest.API { api.On("GetConfig").Return(&model.Config{ ServiceSettings: model.ServiceSettings{ EnableCommands: model.NewBool(true), }, + TeamSettings: model.TeamSettings{ + EnableUserCreation: model.NewBool(true), + }, }) return api @@ -45,7 +48,46 @@ func TestCheckRequiredServerConfiguration(t *testing.T) { ShouldReturn: true, ShouldError: false, }, + "does not contain required configuration": { + SetupAPI: func(api *plugintest.API) *plugintest.API { + api.On("GetConfig").Return(&model.Config{ + ServiceSettings: model.ServiceSettings{ + EnableCommands: model.NewBool(true), + }, + }) + + return api + }, + Input: &model.Config{ + ServiceSettings: model.ServiceSettings{ + EnableCommands: model.NewBool(true), + }, + TeamSettings: model.TeamSettings{ + EnableUserCreation: model.NewBool(true), + }, + }, + ShouldReturn: false, + ShouldError: false, + }, "different configurations": { + SetupAPI: func(api *plugintest.API) *plugintest.API { + api.On("GetConfig").Return(&model.Config{ + ServiceSettings: model.ServiceSettings{ + EnableCommands: model.NewBool(false), + }, + }) + + return api + }, + Input: &model.Config{ + ServiceSettings: model.ServiceSettings{ + EnableCommands: model.NewBool(true), + }, + }, + ShouldReturn: false, + ShouldError: false, + }, + "non-existent configuration": { SetupAPI: func(api *plugintest.API) *plugintest.API { api.On("GetConfig").Return(&model.Config{}) @@ -69,9 +111,7 @@ func TestCheckRequiredServerConfiguration(t *testing.T) { ok, err := p.CheckRequiredServerConfiguration(test.Input) - if !ok { - assert.False(t, ok) - } + assert.Equal(t, test.ShouldReturn, ok) if test.ShouldError { assert.NotNil(t, err) } else {