summaryrefslogtreecommitdiffstats
path: root/api/command_test.go
diff options
context:
space:
mode:
authorDavid Lu <david.lu@hotmail.com>2016-05-27 08:35:55 -0700
committerCorey Hulen <corey@hulen.com>2016-05-27 08:35:55 -0700
commit0d0734ac9845ef32c55ebf4c3185ba85065c5940 (patch)
treeaaaf2522d8cacbf06fce4aee0d89aac1f1d9ec19 /api/command_test.go
parent1e7805b79025823fba4479ffaa354e9c756d6622 (diff)
downloadchat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.tar.gz
chat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.tar.bz2
chat-0d0734ac9845ef32c55ebf4c3185ba85065c5940.zip
Added duplicated trigger validation (#3124)
Diffstat (limited to 'api/command_test.go')
-rw-r--r--api/command_test.go41
1 files changed, 28 insertions, 13 deletions
diff --git a/api/command_test.go b/api/command_test.go
index c6500c6cf..9c0b34085 100644
--- a/api/command_test.go
+++ b/api/command_test.go
@@ -45,16 +45,28 @@ func TestCreateCommand(t *testing.T) {
}()
*utils.Cfg.ServiceSettings.EnableCommands = true
- cmd := &model.Command{URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
+ cmd1 := &model.Command{
+ CreatorId: user.Id,
+ TeamId: team.Id,
+ URL: "http://nowhere.com",
+ Method: model.COMMAND_METHOD_POST,
+ Trigger: "trigger"}
- if _, err := Client.CreateCommand(cmd); err == nil {
+ if _, err := Client.CreateCommand(cmd1); err == nil {
t.Fatal("should have failed because not admin")
}
Client = th.SystemAdminClient
+ cmd2 := &model.Command{
+ CreatorId: user.Id,
+ TeamId: team.Id,
+ URL: "http://nowhere.com",
+ Method: model.COMMAND_METHOD_POST,
+ Trigger: "trigger"}
+
var rcmd *model.Command
- if result, err := Client.CreateCommand(cmd); err != nil {
+ if result, err := Client.CreateCommand(cmd2); err != nil {
t.Fatal(err)
} else {
rcmd = result.Data.(*model.Command)
@@ -68,16 +80,19 @@ func TestCreateCommand(t *testing.T) {
t.Fatal("team ids didn't match")
}
- cmd = &model.Command{CreatorId: "123", TeamId: "456", URL: "http://nowhere.com", Method: model.COMMAND_METHOD_POST, Trigger: "trigger"}
- if result, err := Client.CreateCommand(cmd); err != nil {
- t.Fatal(err)
- } else {
- if result.Data.(*model.Command).CreatorId != user.Id {
- t.Fatal("bad user id wasn't overwritten")
- }
- if result.Data.(*model.Command).TeamId != team.Id {
- t.Fatal("bad team id wasn't overwritten")
- }
+ cmd3 := &model.Command{
+ CreatorId: "123",
+ TeamId: "456",
+ URL: "http://nowhere.com",
+ Method: model.COMMAND_METHOD_POST,
+ Trigger: "trigger"}
+ if _, err := Client.CreateCommand(cmd3); err == nil {
+ t.Fatal("trigger cannot be duplicated")
+ }
+
+ cmd4 := cmd3
+ if _, err := Client.CreateCommand(cmd4); err == nil {
+ t.Fatal("command cannot be duplicated")
}
}