mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
"github.com/mattermost/mattermost-server/utils"
|
|
)
|
|
|
|
func TestCreateWebhookPost(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.App.TearDown()
|
|
|
|
enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
|
|
defer func() {
|
|
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
|
|
utils.SetDefaultRolesBasedOnConfig()
|
|
}()
|
|
utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
|
|
utils.SetDefaultRolesBasedOnConfig()
|
|
|
|
hook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, &model.IncomingWebhook{ChannelId: th.BasicChannel.Id})
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
defer th.App.DeleteIncomingWebhook(hook.Id)
|
|
|
|
post, err := th.App.CreateWebhookPost(hook.UserId, th.BasicChannel, "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)
|
|
}
|
|
}
|
|
}
|