Files
mostlymatter/app/webhook_test.go
Chris df1ff4ec97 PLT-7212: fix missing webhook post attachments (#7011)
* fix missing webhook post attachments

* make ProcessSlackAttachments return a new slice instead of modifying it
2017-08-03 16:25:47 -07:00

48 строки
1.2 KiB
Go

// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package app
import (
"testing"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/utils"
)
func TestCreateWebhookPost(t *testing.T) {
th := Setup().InitBasic()
defer TearDown()
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
defer func() {
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
utils.SetDefaultRolesBasedOnConfig()
}()
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
utils.SetDefaultRolesBasedOnConfig()
hook, err := CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
if err != nil {
t.Fatal(err.Error())
}
defer DeleteIncomingWebhook(hook.Id)
post, err := CreateWebhookPost(hook.UserId, hook.TeamId, th.BasicChannel.Id, "foo", "user", "http://iconurl", model.StringInterface{
"attachments": []*model.SlackAttachment{
&model.SlackAttachment{
Text: "text",
},
},
}, model.POST_SLACK_ATTACHMENT)
if err != nil {
t.Fatal(err.Error())
}
for _, k := range []string{"from_webhook", "attachments"} {
if _, ok := post.Props[k]; !ok {
t.Fatal(k)
}
}
}