diff options
author | Chris <ccbrown112@gmail.com> | 2017-08-16 07:17:57 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-08-16 08:17:57 -0400 |
commit | b122381e87577ddfc12b792a3de9121ea830d50e (patch) | |
tree | 1487a6a97aa0a928db230b207463e721e56858c9 /api4/webhook_test.go | |
parent | 5cd45c939406e5af84b0d9a6967683b77100303c (diff) | |
download | chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.gz chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.bz2 chat-b122381e87577ddfc12b792a3de9121ea830d50e.zip |
PLT-1649: add response_url support for custom slash commands (#6739)
* add response_url support for custom slash commands
* pr suggestions
* pr update / suggestion
* test fix
Diffstat (limited to 'api4/webhook_test.go')
-rw-r--r-- | api4/webhook_test.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/api4/webhook_test.go b/api4/webhook_test.go index 96451f8a7..80328e373 100644 --- a/api4/webhook_test.go +++ b/api4/webhook_test.go @@ -4,8 +4,11 @@ package api4 import ( + "bytes" + "net/http" "testing" + "github.com/mattermost/platform/app" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -893,3 +896,40 @@ func TestDeleteOutgoingHook(t *testing.T) { CheckForbiddenStatus(t, resp) }) } + +func TestCommandWebhooks(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + Client := th.SystemAdminClient + + cmd := &model.Command{ + CreatorId: th.BasicUser.Id, + TeamId: th.BasicTeam.Id, + URL: "http://nowhere.com", + Method: model.COMMAND_METHOD_POST, + Trigger: "delayed"} + + cmd, _ = Client.CreateCommand(cmd) + args := &model.CommandArgs{ + TeamId: th.BasicTeam.Id, + UserId: th.BasicUser.Id, + ChannelId: th.BasicChannel.Id, + } + hook, err := app.CreateCommandWebhook(cmd.Id, args) + if err != nil { + t.Fatal(err) + } + + if resp, _ := http.Post(Client.Url+"/hooks/commands/123123123123", "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); resp.StatusCode != http.StatusNotFound { + t.Fatal("expected not-found for non-existent hook") + } + + for i := 0; i < 5; i++ { + if _, err := http.Post(Client.Url+"/hooks/commands/"+hook.Id, "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); err != nil { + t.Fatal(err) + } + } + + if resp, _ := http.Post(Client.Url+"/hooks/commands/"+hook.Id, "application/json", bytes.NewBufferString("{\"text\":\"this is a test\"}")); resp.StatusCode != http.StatusBadRequest { + t.Fatal("expected error for sixth usage") + } +} |