Files
mattermost/app/webhook_test.go
Chris b066b6df13 Remove global app references (#7433)
* remove global app references

* test fix

* fix api4 test compilation
2017-09-12 09:19:52 -05:00

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)
}
}
}