From df1ff4ec977b76587dfc50885874f08fd9748071 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 3 Aug 2017 18:25:47 -0500 Subject: PLT-7212: fix missing webhook post attachments (#7011) * fix missing webhook post attachments * make ProcessSlackAttachments return a new slice instead of modifying it --- app/webhook_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 app/webhook_test.go (limited to 'app/webhook_test.go') diff --git a/app/webhook_test.go b/app/webhook_test.go new file mode 100644 index 000000000..ae97454a6 --- /dev/null +++ b/app/webhook_test.go @@ -0,0 +1,47 @@ +// 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) + } + } +} -- cgit v1.2.3-1-g7c22