summaryrefslogtreecommitdiffstats
path: root/app/plugin_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-12-08 13:55:41 -0600
committerGitHub <noreply@github.com>2017-12-08 13:55:41 -0600
commit4c17bdff1bb871fb31520b7b547f584c53ed854f (patch)
treeedf1e3295d6ff7d67281efc585b2e913b4efda3d /app/plugin_test.go
parent7ed1177a2b676aa4c93515268642c855cfe57a37 (diff)
downloadchat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.gz
chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.tar.bz2
chat-4c17bdff1bb871fb31520b7b547f584c53ed854f.zip
Add plugin slash command support (#7941)
* add plugin slash command support * remove unused string * rebase
Diffstat (limited to 'app/plugin_test.go')
-rw-r--r--app/plugin_test.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/app/plugin_test.go b/app/plugin_test.go
index 5c70cbc4f..4794d2704 100644
--- a/app/plugin_test.go
+++ b/app/plugin_test.go
@@ -13,6 +13,8 @@ import (
"github.com/stretchr/testify/require"
"github.com/mattermost/mattermost-server/model"
+ "github.com/mattermost/mattermost-server/plugin"
+ "github.com/mattermost/mattermost-server/plugin/plugintest"
)
func TestPluginKeyValueStore(t *testing.T) {
@@ -98,3 +100,98 @@ func TestHandlePluginRequest(t *testing.T) {
}
router.ServeHTTP(nil, r)
}
+
+type testPlugin struct {
+ plugintest.Hooks
+}
+
+func (p *testPlugin) OnConfigurationChange() error {
+ return nil
+}
+
+func (p *testPlugin) OnDeactivate() error {
+ return nil
+}
+
+type pluginCommandTestPlugin struct {
+ testPlugin
+
+ TeamId string
+}
+
+func (p *pluginCommandTestPlugin) OnActivate(api plugin.API) error {
+ if err := api.RegisterCommand(&model.Command{
+ Trigger: "foo",
+ TeamId: p.TeamId,
+ }); err != nil {
+ return err
+ }
+ if err := api.RegisterCommand(&model.Command{
+ Trigger: "foo2",
+ TeamId: p.TeamId,
+ }); err != nil {
+ return err
+ }
+ return api.UnregisterCommand(p.TeamId, "foo2")
+}
+
+func (p *pluginCommandTestPlugin) ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
+ if args.Command == "/foo" {
+ return &model.CommandResponse{
+ Text: "bar",
+ }, nil
+ }
+ return nil, model.NewAppError("ExecuteCommand", "this is an error", nil, "", http.StatusBadRequest)
+}
+
+func TestPluginCommands(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ th.InstallPlugin(&model.Manifest{
+ Id: "foo",
+ }, &pluginCommandTestPlugin{
+ TeamId: th.BasicTeam.Id,
+ })
+
+ require.Nil(t, th.App.EnablePlugin("foo"))
+
+ resp, err := th.App.ExecuteCommand(&model.CommandArgs{
+ Command: "/foo2",
+ TeamId: th.BasicTeam.Id,
+ UserId: th.BasicUser.Id,
+ ChannelId: th.BasicChannel.Id,
+ })
+ require.NotNil(t, err)
+ assert.Equal(t, http.StatusNotFound, err.StatusCode)
+
+ resp, err = th.App.ExecuteCommand(&model.CommandArgs{
+ Command: "/foo",
+ TeamId: th.BasicTeam.Id,
+ UserId: th.BasicUser.Id,
+ ChannelId: th.BasicChannel.Id,
+ })
+ require.Nil(t, err)
+ assert.Equal(t, "bar", resp.Text)
+
+ resp, err = th.App.ExecuteCommand(&model.CommandArgs{
+ Command: "/foo baz",
+ TeamId: th.BasicTeam.Id,
+ UserId: th.BasicUser.Id,
+ ChannelId: th.BasicChannel.Id,
+ })
+ require.NotNil(t, err)
+ require.Equal(t, "this is an error", err.Message)
+ assert.Nil(t, resp)
+
+ require.Nil(t, th.App.RemovePlugin("foo"))
+
+ resp, err = th.App.ExecuteCommand(&model.CommandArgs{
+ Command: "/foo",
+ TeamId: th.BasicTeam.Id,
+ UserId: th.BasicUser.Id,
+ ChannelId: th.BasicChannel.Id,
+ })
+ require.NotNil(t, err)
+ assert.Equal(t, http.StatusNotFound, err.StatusCode)
+}