47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package command
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mattermost/mattermost/server/public/model"
|
|
"github.com/mattermost/mattermost/server/public/plugin/plugintest"
|
|
"github.com/mattermost/mattermost/server/public/pluginapi"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
type env struct {
|
|
client *pluginapi.Client
|
|
api *plugintest.API
|
|
}
|
|
|
|
func setupTest() *env {
|
|
api := &plugintest.API{}
|
|
driver := &plugintest.Driver{}
|
|
client := pluginapi.NewClient(api, driver)
|
|
|
|
return &env{
|
|
client: client,
|
|
api: api,
|
|
}
|
|
}
|
|
|
|
func TestHelloCommand(t *testing.T) {
|
|
assert := assert.New(t)
|
|
env := setupTest()
|
|
|
|
env.api.On("RegisterCommand", &model.Command{
|
|
Trigger: helloCommandTrigger,
|
|
AutoComplete: true,
|
|
AutoCompleteDesc: "Say hello to someone",
|
|
AutoCompleteHint: "[@username]",
|
|
AutocompleteData: model.NewAutocompleteData("hello", "[@username]", "Username to say hello to"),
|
|
}).Return(nil)
|
|
cmdHandler := NewCommandHandler(env.client)
|
|
|
|
args := &model.CommandArgs{
|
|
Command: "/hello world",
|
|
}
|
|
response, err := cmdHandler.Handle(args)
|
|
assert.Nil(err)
|
|
assert.Equal("Hello, world", response.Text)
|
|
}
|