[MM-19153] Add server version check in helper methods for plugins (#12675)

Этот коммит содержится в:
Rajat Varyani
2019-11-06 22:12:46 +05:30
коммит произвёл Ben Schumacher
родитель a39f4f1064
Коммит 14b1777959
5 изменённых файлов: 172 добавлений и 5 удалений

Просмотреть файл

@@ -24,15 +24,37 @@ func TestEnsureBot(t *testing.T) {
Description: "testbotdescription",
}
t.Run("server version incompatible", func(t *testing.T) {
api := setupAPI()
api.On("GetServerVersion").Return("5.9.0")
defer api.AssertExpectations(t)
p := &plugin.HelpersImpl{}
p.API = api
_, retErr := p.EnsureBot(nil)
assert.NotNil(t, retErr)
assert.Equal(t, "failed to ensure bot: incompatible server version for plugin, minimum required version: 5.10.0, current version: 5.9.0", retErr.Error())
})
t.Run("bad parameters", func(t *testing.T) {
t.Run("no bot", func(t *testing.T) {
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
p := &plugin.HelpersImpl{}
p.API = api
botId, err := p.EnsureBot(nil)
assert.Equal(t, "", botId)
assert.NotNil(t, err)
})
t.Run("bad username", func(t *testing.T) {
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
p := &plugin.HelpersImpl{}
p.API = api
botId, err := p.EnsureBot(&model.Bot{
Username: "",
})
@@ -46,6 +68,7 @@ func TestEnsureBot(t *testing.T) {
expectedBotId := model.NewId()
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return([]byte(expectedBotId), nil)
defer api.AssertExpectations(t)
@@ -60,6 +83,7 @@ func TestEnsureBot(t *testing.T) {
t.Run("should return an error if unable to get bot", func(t *testing.T) {
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, &model.AppError{})
defer api.AssertExpectations(t)
@@ -78,6 +102,7 @@ func TestEnsureBot(t *testing.T) {
expectedBotId := model.NewId()
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
api.On("CreateBot", testbot).Return(&model.Bot{
@@ -99,6 +124,7 @@ func TestEnsureBot(t *testing.T) {
expectedBotId := model.NewId()
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(&model.User{
Id: expectedBotId,
@@ -119,6 +145,7 @@ func TestEnsureBot(t *testing.T) {
t.Run("should return the non-bot account but log a message if user exists with the same name and is not a bot", func(t *testing.T) {
expectedBotId := model.NewId()
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(&model.User{
Id: expectedBotId,
@@ -138,6 +165,7 @@ func TestEnsureBot(t *testing.T) {
t.Run("should fail if create bot fails", func(t *testing.T) {
api := setupAPI()
api.On("GetServerVersion").Return("5.10.0")
api.On("KVGet", plugin.BOT_USER_KEY).Return(nil, nil)
api.On("GetUserByUsername", testbot.Username).Return(nil, nil)
api.On("CreateBot", testbot).Return(nil, &model.AppError{})