diff options
author | Artur Mogozov <artur@canva.com> | 2018-10-16 22:13:00 +1100 |
---|---|---|
committer | George Goldberg <george@gberg.me> | 2018-10-16 12:13:00 +0100 |
commit | cedf6488e4d4d66c186facb4253513b1f7e775c6 (patch) | |
tree | 5fb9560e1ec73af6de1e18fa63c322dd5486dba2 /cmd/mattermost/commands/webhook_test.go | |
parent | 80153ef87379040ff1c9ac6f11a7063b743a3fb2 (diff) | |
download | chat-cedf6488e4d4d66c186facb4253513b1f7e775c6.tar.gz chat-cedf6488e4d4d66c186facb4253513b1f7e775c6.tar.bz2 chat-cedf6488e4d4d66c186facb4253513b1f7e775c6.zip |
MM-12368 Add create webhook-incoming command (#9566)
Diffstat (limited to 'cmd/mattermost/commands/webhook_test.go')
-rw-r--r-- | cmd/mattermost/commands/webhook_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/webhook_test.go b/cmd/mattermost/commands/webhook_test.go index cdbe9d7bb..1eea36b76 100644 --- a/cmd/mattermost/commands/webhook_test.go +++ b/cmd/mattermost/commands/webhook_test.go @@ -4,6 +4,7 @@ package commands import ( + "github.com/stretchr/testify/require" "strings" "testing" @@ -49,3 +50,47 @@ func TestListWebhooks(t *testing.T) { } } + +func TestCreateIncomingWebhook(t *testing.T) { + th := api4.Setup().InitBasic().InitSystemAdmin() + defer th.TearDown() + + th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true }) + th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableOutgoingWebhooks = true }) + th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true }) + th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true }) + + defaultRolePermissions := th.SaveDefaultRolePermissions() + defer func() { + th.RestoreDefaultRolePermissions(defaultRolePermissions) + }() + th.AddPermissionToRole(model.PERMISSION_MANAGE_WEBHOOKS.Id, model.TEAM_ADMIN_ROLE_ID) + th.RemovePermissionFromRole(model.PERMISSION_MANAGE_WEBHOOKS.Id, model.TEAM_USER_ROLE_ID) + + // should fail because you need to specify valid channel + require.Error(t, RunCommand(t, "webhook", "create-incoming")) + require.Error(t, RunCommand(t, "webhook", "create-incoming", "--channel", th.BasicTeam.Name+":doesnotexist")) + + // should fail because you need to specify valid user + require.Error(t, RunCommand(t, "webhook", "create-incoming", "--channel", th.BasicChannel.Id)) + require.Error(t, RunCommand(t, "webhook", "create-incoming", "--channel", th.BasicChannel.Id, "--user", "doesnotexist")) + + description := "myhookinc" + displayName := "myhookinc" + CheckCommand(t, "webhook", "create-incoming", "--channel", th.BasicChannel.Id, "--user", th.BasicUser.Email, "--description", description, "--display-name", displayName) + + webhooks, err := th.App.GetIncomingWebhooksPage(0, 1000) + if err != nil { + t.Fatal("unable to retrieve incoming webhooks") + } + + found := false + for _, webhook := range webhooks { + if webhook.Description == description && webhook.UserId == th.BasicUser.Id { + found = true + } + } + if !found { + t.Fatal("Failed to create incoming webhook") + } +} |