From c3993704ef759e1527140b9ed03ed39881cf64f7 Mon Sep 17 00:00:00 2001 From: Artur Mogozov Date: Fri, 19 Oct 2018 22:04:12 +1100 Subject: MM-12372 Add modify-incoming webhook command (#9683) * MM-12372 Add modify-incoming webhook command * Review comments --- cmd/mattermost/commands/webhook_test.go | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'cmd/mattermost/commands/webhook_test.go') diff --git a/cmd/mattermost/commands/webhook_test.go b/cmd/mattermost/commands/webhook_test.go index 1eea36b76..979109676 100644 --- a/cmd/mattermost/commands/webhook_test.go +++ b/cmd/mattermost/commands/webhook_test.go @@ -5,6 +5,7 @@ package commands import ( "github.com/stretchr/testify/require" + "strconv" "strings" "testing" @@ -94,3 +95,58 @@ func TestCreateIncomingWebhook(t *testing.T) { t.Fatal("Failed to create incoming webhook") } } + +func TestModifyIncomingWebhook(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) + + description := "myhookincdesc" + displayName := "myhookincname" + + incomingWebhook := &model.IncomingWebhook{ + ChannelId: th.BasicChannel.Id, + DisplayName: displayName, + Description: description, + } + + oldHook, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, th.BasicChannel, incomingWebhook) + if err != nil { + t.Fatal("unable to create incoming webhooks") + } + defer func() { + th.App.DeleteIncomingWebhook(oldHook.Id) + }() + + // should fail because you need to specify valid incoming webhook + require.Error(t, RunCommand(t, "webhook", "modify-incoming", "doesnotexist")) + // should fail because you need to specify valid channel + require.Error(t, RunCommand(t, "webhook", "modify-incoming", oldHook.Id, "--channel", th.BasicTeam.Name+":doesnotexist")) + + modifiedDescription := "myhookincdesc2" + modifiedDisplayName := "myhookincname2" + modifiedIconUrl := "myhookincicon2" + modifiedChannelLocked := true + modifiedChannelId := th.BasicChannel2.Id + + CheckCommand(t, "webhook", "modify-incoming", oldHook.Id, "--channel", modifiedChannelId, "--description", modifiedDescription, "--display-name", modifiedDisplayName, "--icon", modifiedIconUrl, "--lock-to-channel", strconv.FormatBool(modifiedChannelLocked)) + + modifiedHook, err := th.App.GetIncomingWebhook(oldHook.Id) + if err != nil { + t.Fatal("unable to retrieve modified incoming webhook") + } + if modifiedHook.DisplayName != modifiedDisplayName || modifiedHook.Description != modifiedDescription || modifiedHook.IconURL != modifiedIconUrl || modifiedHook.ChannelLocked != modifiedChannelLocked || modifiedHook.ChannelId != modifiedChannelId { + t.Fatal("Failed to update incoming webhook") + } +} -- cgit v1.2.3-1-g7c22