GH-13421 Autoresponder should not reply to bot DMs (#13583)

Этот коммит содержится в:
Nick Malcev
2020-02-06 16:49:58 +05:00
коммит произвёл GitHub
родитель e965d21359
Коммит 35102b081e
2 изменённых файлов: 37 добавлений и 0 удалений

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

@@ -13,6 +13,10 @@ func (a *App) SendAutoResponseIfNecessary(channel *model.Channel, sender *model.
return false, nil
}
if sender.IsBot {
return false, nil
}
receiverId := channel.GetOtherUserIdForDM(sender.Id)
receiver, err := a.GetUser(receiverId)

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

@@ -135,6 +135,39 @@ func TestSendAutoResponseIfNecessary(t *testing.T) {
assert.Nil(t, err)
assert.False(t, sent)
})
t.Run("should not send auto response for bot", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
receiver := th.CreateUser()
patch := &model.UserPatch{
NotifyProps: map[string]string{
"auto_responder_active": "true",
"auto_responder_message": "Hello, I'm unavailable today.",
},
}
receiver, err := th.App.PatchUser(receiver.Id, patch, true)
require.Nil(t, err)
channel := th.CreateDmChannel(receiver)
bot, err := th.App.CreateBot(&model.Bot{
Username: "botusername",
Description: "bot",
OwnerId: th.BasicUser.Id,
})
assert.Nil(t, err)
botUser, err := th.App.GetUser(bot.UserId)
assert.Nil(t, err)
sent, err := th.App.SendAutoResponseIfNecessary(channel, botUser)
assert.Nil(t, err)
assert.False(t, sent)
})
}
func TestSendAutoResponseSuccess(t *testing.T) {