summaryrefslogtreecommitdiffstats
path: root/plugin/rpcplugin/api_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-08-28 14:19:00 -0500
committerGitHub <noreply@github.com>2017-08-28 14:19:00 -0500
commitff50b0e1382ba0214300ffb8eb467a78dae5b803 (patch)
tree4f11789e8b222a42d9074c46341fff6090b313d2 /plugin/rpcplugin/api_test.go
parent6215c9159acb85033616d2937edf3d87ef7ca79b (diff)
downloadchat-ff50b0e1382ba0214300ffb8eb467a78dae5b803.tar.gz
chat-ff50b0e1382ba0214300ffb8eb467a78dae5b803.tar.bz2
chat-ff50b0e1382ba0214300ffb8eb467a78dae5b803.zip
add client4 apis needed for jira plugin (#7292)
Diffstat (limited to 'plugin/rpcplugin/api_test.go')
-rw-r--r--plugin/rpcplugin/api_test.go50
1 files changed, 49 insertions, 1 deletions
diff --git a/plugin/rpcplugin/api_test.go b/plugin/rpcplugin/api_test.go
index e55433556..7ef9f51a8 100644
--- a/plugin/rpcplugin/api_test.go
+++ b/plugin/rpcplugin/api_test.go
@@ -3,11 +3,13 @@ package rpcplugin
import (
"encoding/json"
"io"
+ "net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
+ "github.com/mattermost/platform/model"
"github.com/mattermost/platform/plugin"
"github.com/mattermost/platform/plugin/plugintest"
)
@@ -47,11 +49,57 @@ func TestAPI(t *testing.T) {
json.Unmarshal([]byte(`{"Foo": "foo", "Bar": {"Baz": "baz"}}`), dest)
}).Return(nil)
+ testChannel := &model.Channel{
+ Id: "thechannelid",
+ }
+
+ testTeam := &model.Team{
+ Id: "theteamid",
+ }
+ teamNotFoundError := model.NewAppError("SqlTeamStore.GetByName", "store.sql_team.get_by_name.app_error", nil, "name=notateam", http.StatusNotFound)
+
+ testUser := &model.User{
+ Id: "theuserid",
+ }
+
+ testPost := &model.Post{
+ Message: "hello",
+ }
+
+ api.On("GetChannelByName", "foo", "theteamid").Return(testChannel, nil)
+ api.On("GetTeamByName", "foo").Return(testTeam, nil)
+ api.On("GetTeamByName", "notateam").Return(nil, teamNotFoundError)
+ api.On("GetUserByUsername", "foo").Return(testUser, nil)
+ api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(func(p *model.Post) (*model.Post, *model.AppError) {
+ p.Id = "thepostid"
+ return p, nil
+ })
+
testAPIRPC(&api, func(remote plugin.API) {
var config Config
assert.NoError(t, remote.LoadPluginConfiguration(&config))
-
assert.Equal(t, "foo", config.Foo)
assert.Equal(t, "baz", config.Bar.Baz)
+
+ channel, err := remote.GetChannelByName("foo", "theteamid")
+ assert.Equal(t, testChannel, channel)
+ assert.Nil(t, err)
+
+ user, err := remote.GetUserByUsername("foo")
+ assert.Equal(t, testUser, user)
+ assert.Nil(t, err)
+
+ team, err := remote.GetTeamByName("foo")
+ assert.Equal(t, testTeam, team)
+ assert.Nil(t, err)
+
+ team, err = remote.GetTeamByName("notateam")
+ assert.Nil(t, team)
+ assert.Equal(t, teamNotFoundError, err)
+
+ post, err := remote.CreatePost(testPost)
+ assert.NotEmpty(t, post.Id)
+ assert.Equal(t, testPost.Message, post.Message)
+ assert.Nil(t, err)
})
}