From c226cabc048a4e33e956346523e4605e85979d08 Mon Sep 17 00:00:00 2001 From: Thomas Balthazar Date: Tue, 31 May 2016 16:51:28 +0200 Subject: PLT-2170 Send payload in application/json for outgoing webhooks (#3160) * Send payload in application/json for outgoing webhooks The Add outgoing webhook UI now has a 'Content-Type' field that allows to choose between application/x-www-form-urlencoded and application/json. All outgoing webhooks created before this change will be considered as x-www-form-urlencoded. There's also a minor change in the way the outgoing webhook summary is displayed: the 'Callback URLs' label was missing. * Fix JS formatting errors * Increase ContentType field length to 128 --- model/outgoing_webhook_test.go | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'model/outgoing_webhook_test.go') diff --git a/model/outgoing_webhook_test.go b/model/outgoing_webhook_test.go index 72c842e03..24b81d221 100644 --- a/model/outgoing_webhook_test.go +++ b/model/outgoing_webhook_test.go @@ -4,6 +4,8 @@ package model import ( + "net/url" + "reflect" "strings" "testing" ) @@ -107,8 +109,49 @@ func TestOutgoingWebhookIsValid(t *testing.T) { o.Description = strings.Repeat("1", 128) if err := o.IsValid(); err != nil { + t.Fatal("should be invalid") + } + + o.ContentType = strings.Repeat("1", 129) + if err := o.IsValid(); err == nil { t.Fatal(err) } + + o.ContentType = strings.Repeat("1", 128) + if err := o.IsValid(); err != nil { + t.Fatal(err) + } +} + +func TestOutgoingWebhookPayloadToFormValues(t *testing.T) { + p := &OutgoingWebhookPayload{ + Token: "Token", + TeamId: "TeamId", + TeamDomain: "TeamDomain", + ChannelId: "ChannelId", + ChannelName: "ChannelName", + Timestamp: 123000, + UserId: "UserId", + UserName: "UserName", + PostId: "PostId", + Text: "Text", + TriggerWord: "TriggerWord", + } + v := url.Values{} + v.Set("token", "Token") + v.Set("team_id", "TeamId") + v.Set("team_domain", "TeamDomain") + v.Set("channel_id", "ChannelId") + v.Set("channel_name", "ChannelName") + v.Set("timestamp", "123") + v.Set("user_id", "UserId") + v.Set("user_name", "UserName") + v.Set("post_id", "PostId") + v.Set("text", "Text") + v.Set("trigger_word", "TriggerWord") + if got, want := p.ToFormValues(), v.Encode(); !reflect.DeepEqual(got, want) { + t.Fatalf("Got %+v, wanted %+v", got, want) + } } func TestOutgoingWebhookPreSave(t *testing.T) { -- cgit v1.2.3-1-g7c22