Gh 13908 fix bot missing username error (#17854)

Automatic Merge
Этот коммит содержится в:
Sorawis Nilparuk (Bo)
2021-09-03 01:29:01 -07:00
коммит произвёл GitHub
родитель 236d46ecc6
Коммит f2c955b3d3
3 изменённых файлов: 30 добавлений и 9 удалений

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

@@ -18,6 +18,11 @@ import (
// CreateBot creates the given bot and corresponding user.
func (a *App) CreateBot(c *request.Context, bot *model.Bot) (*model.Bot, *model.AppError) {
vErr := bot.IsValidCreate()
if vErr != nil {
return nil, vErr
}
user, nErr := a.Srv().Store.User().Save(model.UserFromBot(bot))
if nErr != nil {
var appErr *model.AppError

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

@@ -26,7 +26,7 @@ func TestCreateBot(t *testing.T) {
OwnerId: th.BasicUser.Id,
})
require.NotNil(t, err)
require.Equal(t, "model.user.is_valid.username.app_error", err.Id)
require.Equal(t, "model.bot.is_valid.username.app_error", err.Id)
})
t.Run("relative to bot", func(t *testing.T) {
@@ -55,6 +55,18 @@ func TestCreateBot(t *testing.T) {
require.Nil(t, bot)
require.Equal(t, "model.user.is_valid.email.app_error", err.Id)
})
t.Run("username missing", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
bot, err := th.App.CreateBot(th.Context, &model.Bot{
Description: "a bot",
OwnerId: th.BasicUser.Id,
})
require.NotNil(t, err)
require.Nil(t, bot)
require.Equal(t, "model.bot.is_valid.username.app_error", err.Id)
})
})
t.Run("create bot", func(t *testing.T) {