summaryrefslogtreecommitdiffstats
path: root/api4/command_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-04-10 22:27:10 +0900
committerHarrison Healey <harrisonmhealey@gmail.com>2017-04-10 09:27:10 -0400
commit3b1088f3bdb43125d81645697dfd70bdae033bfc (patch)
tree591eeb1c88b7db52f274db0594cfa3377df0f8d4 /api4/command_test.go
parent38eced02908ea95cc2a52167d48c086d09db3532 (diff)
downloadchat-3b1088f3bdb43125d81645697dfd70bdae033bfc.tar.gz
chat-3b1088f3bdb43125d81645697dfd70bdae033bfc.tar.bz2
chat-3b1088f3bdb43125d81645697dfd70bdae033bfc.zip
APIv4 DELETE /commands/{command_id} (#6012)
Diffstat (limited to 'api4/command_test.go')
-rw-r--r--api4/command_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/api4/command_test.go b/api4/command_test.go
index 35fc0a3d5..6c100ed08 100644
--- a/api4/command_test.go
+++ b/api4/command_test.go
@@ -146,6 +146,69 @@ func TestUpdateCommand(t *testing.T) {
CheckUnauthorizedStatus(t, resp)
}
+func TestDeleteCommand(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.SystemAdminClient
+ user := th.SystemAdminUser
+ team := th.BasicTeam
+
+ enableCommands := *utils.Cfg.ServiceSettings.EnableCommands
+ defer func() {
+ utils.Cfg.ServiceSettings.EnableCommands = &enableCommands
+ }()
+ *utils.Cfg.ServiceSettings.EnableCommands = true
+
+ cmd1 := &model.Command{
+ CreatorId: user.Id,
+ TeamId: team.Id,
+ URL: "http://nowhere.com",
+ Method: model.COMMAND_METHOD_POST,
+ Trigger: "trigger1",
+ }
+
+ rcmd1, _ := app.CreateCommand(cmd1)
+
+ ok, resp := Client.DeleteCommand(rcmd1.Id)
+ CheckNoError(t, resp)
+
+ if !ok {
+ t.Fatal("should have returned true")
+ }
+
+ rcmd1, _ = app.GetCommand(rcmd1.Id)
+ if rcmd1 != nil {
+ t.Fatal("should be nil")
+ }
+
+ ok, resp = Client.DeleteCommand("junk")
+ CheckBadRequestStatus(t, resp)
+
+ if ok {
+ t.Fatal("should have returned false")
+ }
+
+ _, resp = Client.DeleteCommand(GenerateTestId())
+ CheckNotFoundStatus(t, resp)
+
+ cmd2 := &model.Command{
+ CreatorId: user.Id,
+ TeamId: team.Id,
+ URL: "http://nowhere.com",
+ Method: model.COMMAND_METHOD_POST,
+ Trigger: "trigger2",
+ }
+
+ rcmd2, _ := app.CreateCommand(cmd2)
+
+ _, resp = th.Client.DeleteCommand(rcmd2.Id)
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.DeleteCommand(rcmd2.Id)
+ CheckUnauthorizedStatus(t, resp)
+}
+
func TestListCommands(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()