summaryrefslogtreecommitdiffstats
path: root/cmd/mattermost/commands/command_test.go
diff options
context:
space:
mode:
authorShobhit Gupta <smartyshobhit@gmail.com>2018-10-23 04:19:10 -0700
committerGeorge Goldberg <george@gberg.me>2018-10-23 12:19:10 +0100
commitc317d6f2656d864a2031d0ac8898a3c46d2c93cc (patch)
treeff58ed977a0d38d3a7918f8b056f33feea9fe0c4 /cmd/mattermost/commands/command_test.go
parent6232ff3738a2e5e52469dc23840bb96385b5d8ea (diff)
downloadchat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.tar.gz
chat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.tar.bz2
chat-c317d6f2656d864a2031d0ac8898a3c46d2c93cc.zip
MM-12356 Add cli command "command delete" (#9553)
* Add cli command for deleting commands * Add code/test for delete command * Fix test * Add confirm flag * Update as per comments * Uncomment test * Fix test
Diffstat (limited to 'cmd/mattermost/commands/command_test.go')
-rw-r--r--cmd/mattermost/commands/command_test.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmd/mattermost/commands/command_test.go b/cmd/mattermost/commands/command_test.go
index 4e54c56b4..73ebacd08 100644
--- a/cmd/mattermost/commands/command_test.go
+++ b/cmd/mattermost/commands/command_test.go
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/mattermost/mattermost-server/api4"
+ "github.com/mattermost/mattermost-server/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -126,3 +127,34 @@ func TestCreateCommand(t *testing.T) {
})
}
}
+
+func TestDeleteCommand(t *testing.T) {
+ th := api4.Setup().InitBasic()
+ defer th.TearDown()
+ url := "http://localhost:8000/test-command"
+ team := th.BasicTeam
+ user := th.BasicUser
+ th.LinkUserToTeam(user, team)
+
+ // Check the appropriate permissions are enforced.
+ defaultRolePermissions := th.SaveDefaultRolePermissions()
+ defer func() {
+ th.RestoreDefaultRolePermissions(defaultRolePermissions)
+ }()
+ id := model.NewId()
+ c := &model.Command{
+ DisplayName: "dn_" + id,
+ Method: "G",
+ TeamId: team.Id,
+ Username: user.Username,
+ URL: url,
+ Trigger: "test",
+ }
+ th.AddPermissionToRole(model.PERMISSION_MANAGE_SLASH_COMMANDS.Id, model.TEAM_USER_ROLE_ID)
+ command, _ := th.Client.CreateCommand(c)
+ commands, _ := th.Client.ListCommands(team.Id, true)
+ assert.Equal(t, len(commands), 1)
+ CheckCommand(t, "command", "delete", command.Id)
+ commands, _ = th.Client.ListCommands(team.Id, true)
+ assert.Equal(t, len(commands), 0)
+}