summaryrefslogtreecommitdiffstats
path: root/api4/webhook_test.go
diff options
context:
space:
mode:
authorJesse Hallam <jesse.hallam@gmail.com>2018-01-02 11:41:23 -0500
committerChristopher Speller <crspeller@gmail.com>2018-01-02 08:41:23 -0800
commite9fe9f50dd5839a7cf0926a2d97e88a19c9b831e (patch)
tree87073ea7310a356b4f2d78a5b5f569730ef89257 /api4/webhook_test.go
parentb902e4eea9732573d3a3dc9f6a62ca7029cac409 (diff)
downloadchat-e9fe9f50dd5839a7cf0926a2d97e88a19c9b831e.tar.gz
chat-e9fe9f50dd5839a7cf0926a2d97e88a19c9b831e.tar.bz2
chat-e9fe9f50dd5839a7cf0926a2d97e88a19c9b831e.zip
[PLT-8173] Add username and profile picture to webhook set up pages (#8002)
Diffstat (limited to 'api4/webhook_test.go')
-rw-r--r--api4/webhook_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/api4/webhook_test.go b/api4/webhook_test.go
index 4a3520bd4..464245259 100644
--- a/api4/webhook_test.go
+++ b/api4/webhook_test.go
@@ -20,6 +20,8 @@ func TestCreateIncomingWebhook(t *testing.T) {
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = true })
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.EnableOnlyAdminIntegrations = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true })
hook := &model.IncomingWebhook{ChannelId: th.BasicChannel.Id}
@@ -56,6 +58,12 @@ func TestCreateIncomingWebhook(t *testing.T) {
_, resp = Client.CreateIncomingWebhook(hook)
CheckNoError(t, resp)
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = false })
+
+ _, resp = Client.CreateIncomingWebhook(hook)
+ CheckNoError(t, resp)
+
th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnableIncomingWebhooks = false })
_, resp = Client.CreateIncomingWebhook(hook)
CheckNotImplementedStatus(t, resp)
@@ -410,10 +418,55 @@ func TestUpdateIncomingHook(t *testing.T) {
createdHook, resp := th.SystemAdminClient.CreateIncomingWebhook(hook1)
CheckNoError(t, resp)
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = false })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = false })
+
+ t.Run("UpdateIncomingHook, overrides disabled", func(t *testing.T) {
+ createdHook.DisplayName = "hook2"
+ createdHook.Description = "description"
+ createdHook.ChannelId = th.BasicChannel2.Id
+ createdHook.PostUsername = "username"
+ createdHook.PostIconURL = "icon"
+
+ updatedHook, resp := th.SystemAdminClient.UpdateIncomingWebhook(createdHook)
+ CheckNoError(t, resp)
+ if updatedHook != nil {
+ if updatedHook.DisplayName != "hook2" {
+ t.Fatal("Hook name is not updated")
+ }
+
+ if updatedHook.Description != "description" {
+ t.Fatal("Hook description is not updated")
+ }
+
+ if updatedHook.ChannelId != th.BasicChannel2.Id {
+ t.Fatal("Hook channel is not updated")
+ }
+
+ if updatedHook.PostUsername != "" {
+ t.Fatal("Hook username was incorrectly updated")
+ }
+
+ if updatedHook.PostIconURL != "" {
+ t.Fatal("Hook icon was incorrectly updated")
+ }
+ } else {
+ t.Fatal("should not be nil")
+ }
+
+ //updatedHook, _ = th.App.GetIncomingWebhook(createdHook.Id)
+ assert.Equal(t, updatedHook.ChannelId, createdHook.ChannelId)
+ })
+
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostUsernameOverride = true })
+ th.App.UpdateConfig(func(cfg *model.Config) { cfg.ServiceSettings.EnablePostIconOverride = true })
+
t.Run("UpdateIncomingHook", func(t *testing.T) {
createdHook.DisplayName = "hook2"
createdHook.Description = "description"
createdHook.ChannelId = th.BasicChannel2.Id
+ createdHook.PostUsername = "username"
+ createdHook.PostIconURL = "icon"
updatedHook, resp := th.SystemAdminClient.UpdateIncomingWebhook(createdHook)
CheckNoError(t, resp)
@@ -429,6 +482,14 @@ func TestUpdateIncomingHook(t *testing.T) {
if updatedHook.ChannelId != th.BasicChannel2.Id {
t.Fatal("Hook channel is not updated")
}
+
+ if updatedHook.PostUsername != "username" {
+ t.Fatal("Hook username is not updated")
+ }
+
+ if updatedHook.PostIconURL != "icon" {
+ t.Fatal("Hook icon is not updated")
+ }
} else {
t.Fatal("should not be nil")
}