summaryrefslogtreecommitdiffstats
path: root/api/webhook_test.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-28 04:31:53 -0500
committerGeorge Goldberg <george@gberg.me>2017-02-28 09:31:53 +0000
commit76fa840b52ea79f05e5e681abca92b279de78182 (patch)
treecf910b49679e0efcbd05851dde00e42eeefc1632 /api/webhook_test.go
parentcef5028cbeed93b6493f6d1f379afe4ca85535c8 (diff)
downloadchat-76fa840b52ea79f05e5e681abca92b279de78182.tar.gz
chat-76fa840b52ea79f05e5e681abca92b279de78182.tar.bz2
chat-76fa840b52ea79f05e5e681abca92b279de78182.zip
Move webhook logic from api layer to app layer (#5527)
* Move webhook logic from api layer to app layer * Consolidate error messages * Fix permission check and unit test
Diffstat (limited to 'api/webhook_test.go')
-rw-r--r--api/webhook_test.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/api/webhook_test.go b/api/webhook_test.go
index dc708cf76..8a170bd9a 100644
--- a/api/webhook_test.go
+++ b/api/webhook_test.go
@@ -716,19 +716,17 @@ func TestUpdateOutgoingHook(t *testing.T) {
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)
- t.Run("UpdateByUserWithoutPermissions", func(t *testing.T) {
- if _, err := Client.UpdateOutgoingWebhook(hook); err == nil {
- t.Fatal("should have failed - user does not have permissions to manage webhooks")
- }
+ if _, err := Client.UpdateOutgoingWebhook(hook); err == nil {
+ t.Fatal("should have failed - user does not have permissions to manage webhooks")
+ }
- *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
- utils.SetDefaultRolesBasedOnConfig()
- t.Run("WithoutOnlyAdminIntegrations", func(t *testing.T) {
- if _, err := Client.UpdateOutgoingWebhook(hook); err != nil {
- t.Fatal("update webhook failed when admin only integrations is turned off")
- }
- })
- })
+ *utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = false
+ utils.SetDefaultRolesBasedOnConfig()
+ hook2 := createOutgoingWebhook(channel1.Id, []string{"http://nowhereelse.com"}, []string{"dogs"}, Client, t)
+
+ if _, err := Client.UpdateOutgoingWebhook(hook2); err != nil {
+ t.Fatal("update webhook failed when admin only integrations is turned off")
+ }
*utils.Cfg.ServiceSettings.EnableOnlyAdminIntegrations = true
utils.SetDefaultRolesBasedOnConfig()
@@ -919,6 +917,11 @@ func TestRegenOutgoingHookToken(t *testing.T) {
}
}
+ Client.SetTeamId(model.NewId())
+ if _, err := Client.RegenOutgoingWebhookToken(hook.Id); err == nil {
+ t.Fatal("should have failed - wrong team id")
+ }
+
Client.Logout()
Client.Must(Client.LoginById(user2.Id, user2.Password))
Client.SetTeamId(team.Id)