Initial commit from mattermost-plugin-starter-template
This commit is contained in:
commit
acbc69f7eb
57 changed files with 27772 additions and 0 deletions
47
server/command/command_test.go
Normal file
47
server/command/command_test.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue