summaryrefslogtreecommitdiffstats
path: root/api4/webhook_test.go
diff options
context:
space:
mode:
authorCarlos Tadeu Panato Junior <ctadeu@gmail.com>2017-03-23 13:50:06 +0100
committerGeorge Goldberg <george@gberg.me>2017-03-23 12:50:06 +0000
commit34cb70d005ba5ebea7398646db6e242baa81b701 (patch)
tree086f4bd61c82aa0b807df028ab1dab63e19b7dc6 /api4/webhook_test.go
parent94b4aa082c456914d89d9926d06814bd17309a73 (diff)
downloadchat-34cb70d005ba5ebea7398646db6e242baa81b701.tar.gz
chat-34cb70d005ba5ebea7398646db6e242baa81b701.tar.bz2
chat-34cb70d005ba5ebea7398646db6e242baa81b701.zip
add implementation for endpoint DELETE outgoing webhook for apiv4 (#5828)
Diffstat (limited to 'api4/webhook_test.go')
-rw-r--r--api4/webhook_test.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/api4/webhook_test.go b/api4/webhook_test.go
index 80b03c5aa..1691b27e5 100644
--- a/api4/webhook_test.go
+++ b/api4/webhook_test.go
@@ -831,3 +831,65 @@ func TestUpdateOutgoingHook(t *testing.T) {
CheckUnauthorizedStatus(t, resp)
})
}
+
+func TestDeleteOutgoingHook(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.SystemAdminClient
+
+ enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks
+ enableAdminOnlyHooks := utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations
+ defer func() {
+ utils.Cfg.ServiceSettings.EnableIncomingWebhooks = enableIncomingHooks
+ utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = enableAdminOnlyHooks
+ utils.SetDefaultRolesBasedOnConfig()
+ }()
+ utils.Cfg.ServiceSettings.EnableIncomingWebhooks = true
+ *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
+ utils.SetDefaultRolesBasedOnConfig()
+
+ var resp *model.Response
+ var rhook *model.OutgoingWebhook
+ var hook *model.OutgoingWebhook
+ var status bool
+
+ t.Run("WhenInvalidHookID", func(t *testing.T) {
+ status, resp = Client.DeleteOutgoingWebhook("abc")
+ CheckBadRequestStatus(t, resp)
+ })
+
+ t.Run("WhenHookDoesNotExist", func(t *testing.T) {
+ status, resp = Client.DeleteOutgoingWebhook(model.NewId())
+ CheckInternalErrorStatus(t, resp)
+ })
+
+ t.Run("WhenHookExists", func(t *testing.T) {
+ hook = &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
+ CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"cats"}}
+ rhook, resp = Client.CreateOutgoingWebhook(hook)
+ CheckNoError(t, resp)
+
+ if status, resp = Client.DeleteOutgoingWebhook(rhook.Id); !status {
+ t.Fatal("Delete should have succeeded")
+ } else {
+ CheckOKStatus(t, resp)
+ }
+
+ // Get now should not return this deleted hook
+ _, resp = Client.GetIncomingWebhook(rhook.Id, "")
+ CheckNotFoundStatus(t, resp)
+ })
+
+ t.Run("WhenUserDoesNotHavePemissions", func(t *testing.T) {
+ hook = &model.OutgoingWebhook{ChannelId: th.BasicChannel.Id, TeamId: th.BasicChannel.TeamId,
+ CallbackURLs: []string{"http://nowhere.com"}, TriggerWords: []string{"dogs"}}
+ rhook, resp = Client.CreateOutgoingWebhook(hook)
+ CheckNoError(t, resp)
+
+ th.LoginBasic()
+ Client = th.Client
+
+ _, resp = Client.DeleteOutgoingWebhook(rhook.Id)
+ CheckForbiddenStatus(t, resp)
+ })
+}