summaryrefslogtreecommitdiffstats
path: root/model/command_webhook_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-08-16 07:17:57 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-08-16 08:17:57 -0400
commitb122381e87577ddfc12b792a3de9121ea830d50e (patch)
tree1487a6a97aa0a928db230b207463e721e56858c9 /model/command_webhook_test.go
parent5cd45c939406e5af84b0d9a6967683b77100303c (diff)
downloadchat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.gz
chat-b122381e87577ddfc12b792a3de9121ea830d50e.tar.bz2
chat-b122381e87577ddfc12b792a3de9121ea830d50e.zip
PLT-1649: add response_url support for custom slash commands (#6739)
* add response_url support for custom slash commands * pr suggestions * pr update / suggestion * test fix
Diffstat (limited to 'model/command_webhook_test.go')
-rw-r--r--model/command_webhook_test.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/model/command_webhook_test.go b/model/command_webhook_test.go
new file mode 100644
index 000000000..629bbdaa7
--- /dev/null
+++ b/model/command_webhook_test.go
@@ -0,0 +1,54 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "testing"
+)
+
+func TestCommandWebhookPreSave(t *testing.T) {
+ h := CommandWebhook{}
+ h.PreSave()
+ if len(h.Id) != 26 {
+ t.Fatal("Id should be generated")
+ }
+ if h.CreateAt == 0 {
+ t.Fatal("CreateAt should be set")
+ }
+}
+
+func TestCommandWebhookIsValid(t *testing.T) {
+ h := CommandWebhook{}
+ h.Id = NewId()
+ h.CreateAt = GetMillis()
+ h.CommandId = NewId()
+ h.UserId = NewId()
+ h.ChannelId = NewId()
+
+ for _, test := range []struct {
+ Transform func()
+ ExpectedError string
+ }{
+ {func() {}, ""},
+ {func() { h.Id = "asd" }, "model.command_hook.id.app_error"},
+ {func() { h.CreateAt = 0 }, "model.command_hook.create_at.app_error"},
+ {func() { h.CommandId = "asd" }, "model.command_hook.command_id.app_error"},
+ {func() { h.UserId = "asd" }, "model.command_hook.user_id.app_error"},
+ {func() { h.ChannelId = "asd" }, "model.command_hook.channel_id.app_error"},
+ {func() { h.RootId = "asd" }, "model.command_hook.root_id.app_error"},
+ {func() { h.RootId = NewId() }, ""},
+ {func() { h.ParentId = "asd" }, "model.command_hook.parent_id.app_error"},
+ {func() { h.ParentId = NewId() }, ""},
+ } {
+ tmp := h
+ test.Transform()
+ err := h.IsValid()
+ if test.ExpectedError == "" && err != nil {
+ t.Fatal("hook should be valid")
+ } else if test.ExpectedError != "" && test.ExpectedError != err.Id {
+ t.Fatal("expected " + test.ExpectedError + " error")
+ }
+ h = tmp
+ }
+}