mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
plugin CRUD operations for users, posts, channels, and teams (#7479)
This commit is contained in:
@@ -28,11 +28,40 @@ func (api *LocalAPI) LoadPluginConfiguration(args struct{}, reply *[]byte) error
|
||||
return nil
|
||||
}
|
||||
|
||||
type APIErrorReply struct {
|
||||
Error *model.AppError
|
||||
}
|
||||
|
||||
type APITeamReply struct {
|
||||
Team *model.Team
|
||||
Error *model.AppError
|
||||
}
|
||||
|
||||
func (api *LocalAPI) CreateTeam(args *model.Team, reply *APITeamReply) error {
|
||||
team, err := api.api.CreateTeam(args)
|
||||
*reply = APITeamReply{
|
||||
Team: team,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) DeleteTeam(args string, reply *APIErrorReply) error {
|
||||
*reply = APIErrorReply{
|
||||
Error: api.api.DeleteTeam(args),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetTeam(args string, reply *APITeamReply) error {
|
||||
team, err := api.api.GetTeam(args)
|
||||
*reply = APITeamReply{
|
||||
Team: team,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetTeamByName(args string, reply *APITeamReply) error {
|
||||
team, err := api.api.GetTeamByName(args)
|
||||
*reply = APITeamReply{
|
||||
@@ -42,11 +71,54 @@ func (api *LocalAPI) GetTeamByName(args string, reply *APITeamReply) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) UpdateTeam(args *model.Team, reply *APITeamReply) error {
|
||||
team, err := api.api.UpdateTeam(args)
|
||||
*reply = APITeamReply{
|
||||
Team: team,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type APIUserReply struct {
|
||||
User *model.User
|
||||
Error *model.AppError
|
||||
}
|
||||
|
||||
func (api *LocalAPI) CreateUser(args *model.User, reply *APIUserReply) error {
|
||||
user, err := api.api.CreateUser(args)
|
||||
*reply = APIUserReply{
|
||||
User: user,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) DeleteUser(args string, reply *APIErrorReply) error {
|
||||
*reply = APIErrorReply{
|
||||
Error: api.api.DeleteUser(args),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetUser(args string, reply *APIUserReply) error {
|
||||
user, err := api.api.GetUser(args)
|
||||
*reply = APIUserReply{
|
||||
User: user,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetUserByEmail(args string, reply *APIUserReply) error {
|
||||
user, err := api.api.GetUserByEmail(args)
|
||||
*reply = APIUserReply{
|
||||
User: user,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetUserByUsername(args string, reply *APIUserReply) error {
|
||||
user, err := api.api.GetUserByUsername(args)
|
||||
*reply = APIUserReply{
|
||||
@@ -56,16 +128,59 @@ func (api *LocalAPI) GetUserByUsername(args string, reply *APIUserReply) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) UpdateUser(args *model.User, reply *APIUserReply) error {
|
||||
user, err := api.api.UpdateUser(args)
|
||||
*reply = APIUserReply{
|
||||
User: user,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type APIGetChannelByNameArgs struct {
|
||||
Name string
|
||||
TeamId string
|
||||
}
|
||||
|
||||
type APIGetDirectChannelArgs struct {
|
||||
UserId1 string
|
||||
UserId2 string
|
||||
}
|
||||
|
||||
type APIGetGroupChannelArgs struct {
|
||||
UserIds []string
|
||||
}
|
||||
|
||||
type APIChannelReply struct {
|
||||
Channel *model.Channel
|
||||
Error *model.AppError
|
||||
}
|
||||
|
||||
func (api *LocalAPI) CreateChannel(args *model.Channel, reply *APIChannelReply) error {
|
||||
channel, err := api.api.CreateChannel(args)
|
||||
*reply = APIChannelReply{
|
||||
Channel: channel,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) DeleteChannel(args string, reply *APIErrorReply) error {
|
||||
*reply = APIErrorReply{
|
||||
Error: api.api.DeleteChannel(args),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetChannel(args string, reply *APIChannelReply) error {
|
||||
channel, err := api.api.GetChannel(args)
|
||||
*reply = APIChannelReply{
|
||||
Channel: channel,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetChannelByName(args *APIGetChannelByNameArgs, reply *APIChannelReply) error {
|
||||
channel, err := api.api.GetChannelByName(args.Name, args.TeamId)
|
||||
*reply = APIChannelReply{
|
||||
@@ -75,6 +190,33 @@ func (api *LocalAPI) GetChannelByName(args *APIGetChannelByNameArgs, reply *APIC
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetDirectChannel(args *APIGetDirectChannelArgs, reply *APIChannelReply) error {
|
||||
channel, err := api.api.GetDirectChannel(args.UserId1, args.UserId2)
|
||||
*reply = APIChannelReply{
|
||||
Channel: channel,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetGroupChannel(args *APIGetGroupChannelArgs, reply *APIChannelReply) error {
|
||||
channel, err := api.api.GetGroupChannel(args.UserIds)
|
||||
*reply = APIChannelReply{
|
||||
Channel: channel,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) UpdateChannel(args *model.Channel, reply *APIChannelReply) error {
|
||||
channel, err := api.api.UpdateChannel(args)
|
||||
*reply = APIChannelReply{
|
||||
Channel: channel,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type APIPostReply struct {
|
||||
Post *model.Post
|
||||
Error *model.AppError
|
||||
@@ -89,6 +231,31 @@ func (api *LocalAPI) CreatePost(args *model.Post, reply *APIPostReply) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) DeletePost(args string, reply *APIErrorReply) error {
|
||||
*reply = APIErrorReply{
|
||||
Error: api.api.DeletePost(args),
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) GetPost(args string, reply *APIPostReply) error {
|
||||
post, err := api.api.GetPost(args)
|
||||
*reply = APIPostReply{
|
||||
Post: post,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *LocalAPI) UpdatePost(args *model.Post, reply *APIPostReply) error {
|
||||
post, err := api.api.UpdatePost(args)
|
||||
*reply = APIPostReply{
|
||||
Post: post,
|
||||
Error: err,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ServeAPI(api plugin.API, conn io.ReadWriteCloser, muxer *Muxer) {
|
||||
server := rpc.NewServer()
|
||||
server.Register(&LocalAPI{
|
||||
@@ -113,12 +280,36 @@ func (api *RemoteAPI) LoadPluginConfiguration(dest interface{}) error {
|
||||
return json.Unmarshal(config, dest)
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetTeamByName(name string) (*model.Team, *model.AppError) {
|
||||
var reply APITeamReply
|
||||
if err := api.client.Call("LocalAPI.GetTeamByName", name, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetTeamByName", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
func (api *RemoteAPI) CreateUser(user *model.User) (*model.User, *model.AppError) {
|
||||
var reply APIUserReply
|
||||
if err := api.client.Call("LocalAPI.CreateUser", user, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.CreateUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Team, reply.Error
|
||||
return reply.User, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) DeleteUser(userId string) *model.AppError {
|
||||
var reply APIErrorReply
|
||||
if err := api.client.Call("LocalAPI.DeleteUser", userId, &reply); err != nil {
|
||||
return model.NewAppError("RemoteAPI.DeleteUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetUser(userId string) (*model.User, *model.AppError) {
|
||||
var reply APIUserReply
|
||||
if err := api.client.Call("LocalAPI.GetUser", userId, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.User, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetUserByEmail(email string) (*model.User, *model.AppError) {
|
||||
var reply APIUserReply
|
||||
if err := api.client.Call("LocalAPI.GetUserByEmail", email, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetUserByEmail", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.User, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetUserByUsername(name string) (*model.User, *model.AppError) {
|
||||
@@ -129,6 +320,78 @@ func (api *RemoteAPI) GetUserByUsername(name string) (*model.User, *model.AppErr
|
||||
return reply.User, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {
|
||||
var reply APIUserReply
|
||||
if err := api.client.Call("LocalAPI.UpdateUser", user, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.UpdateUser", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.User, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) CreateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
||||
var reply APITeamReply
|
||||
if err := api.client.Call("LocalAPI.CreateTeam", team, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.CreateTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Team, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) DeleteTeam(teamId string) *model.AppError {
|
||||
var reply APIErrorReply
|
||||
if err := api.client.Call("LocalAPI.DeleteTeam", teamId, &reply); err != nil {
|
||||
return model.NewAppError("RemoteAPI.DeleteTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetTeam(teamId string) (*model.Team, *model.AppError) {
|
||||
var reply APITeamReply
|
||||
if err := api.client.Call("LocalAPI.GetTeam", teamId, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Team, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetTeamByName(name string) (*model.Team, *model.AppError) {
|
||||
var reply APITeamReply
|
||||
if err := api.client.Call("LocalAPI.GetTeamByName", name, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetTeamByName", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Team, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
|
||||
var reply APITeamReply
|
||||
if err := api.client.Call("LocalAPI.UpdateTeam", team, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.UpdateTeam", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Team, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.CreateChannel", channel, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.CreateChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) DeleteChannel(channelId string) *model.AppError {
|
||||
var reply APIErrorReply
|
||||
if err := api.client.Call("LocalAPI.DeleteChannel", channelId, &reply); err != nil {
|
||||
return model.NewAppError("RemoteAPI.DeleteChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetChannel(channelId string) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.GetChannel", channelId, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetChannelByName(name, teamId string) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.GetChannelByName", &APIGetChannelByNameArgs{
|
||||
@@ -140,6 +403,35 @@ func (api *RemoteAPI) GetChannelByName(name, teamId string) (*model.Channel, *mo
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetDirectChannel(userId1, userId2 string) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.GetDirectChannel", &APIGetDirectChannelArgs{
|
||||
UserId1: userId1,
|
||||
UserId2: userId2,
|
||||
}, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetDirectChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetGroupChannel(userIds []string) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.GetGroupChannel", &APIGetGroupChannelArgs{
|
||||
UserIds: userIds,
|
||||
}, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetGroupChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppError) {
|
||||
var reply APIChannelReply
|
||||
if err := api.client.Call("LocalAPI.UpdateChannel", channel, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.UpdateChannel", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Channel, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||
var reply APIPostReply
|
||||
if err := api.client.Call("LocalAPI.CreatePost", post, &reply); err != nil {
|
||||
@@ -148,6 +440,30 @@ func (api *RemoteAPI) CreatePost(post *model.Post) (*model.Post, *model.AppError
|
||||
return reply.Post, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) DeletePost(postId string) *model.AppError {
|
||||
var reply APIErrorReply
|
||||
if err := api.client.Call("LocalAPI.DeletePost", postId, &reply); err != nil {
|
||||
return model.NewAppError("RemoteAPI.DeletePost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) GetPost(postId string) (*model.Post, *model.AppError) {
|
||||
var reply APIPostReply
|
||||
if err := api.client.Call("LocalAPI.GetPost", postId, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.GetPost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Post, reply.Error
|
||||
}
|
||||
|
||||
func (api *RemoteAPI) UpdatePost(post *model.Post) (*model.Post, *model.AppError) {
|
||||
var reply APIPostReply
|
||||
if err := api.client.Call("LocalAPI.UpdatePost", post, &reply); err != nil {
|
||||
return nil, model.NewAppError("RemoteAPI.UpdatePost", "plugin.rpcplugin.invocation.error", nil, "err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
return reply.Post, reply.Error
|
||||
}
|
||||
|
||||
func (h *RemoteAPI) Close() error {
|
||||
return h.client.Close()
|
||||
}
|
||||
|
||||
@@ -66,40 +66,138 @@ func TestAPI(t *testing.T) {
|
||||
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")
|
||||
api.On("CreateChannel", mock.AnythingOfType("*model.Channel")).Return(func(c *model.Channel) (*model.Channel, *model.AppError) {
|
||||
c.Id = "thechannelid"
|
||||
return c, nil
|
||||
}).Once()
|
||||
channel, err := remote.CreateChannel(testChannel)
|
||||
assert.Equal(t, "thechannelid", channel.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("DeleteChannel", "thechannelid").Return(nil).Once()
|
||||
assert.Nil(t, remote.DeleteChannel("thechannelid"))
|
||||
|
||||
api.On("GetChannel", "thechannelid").Return(testChannel, nil).Once()
|
||||
channel, err = remote.GetChannel("thechannelid")
|
||||
assert.Equal(t, testChannel, channel)
|
||||
assert.Nil(t, err)
|
||||
|
||||
user, err := remote.GetUserByUsername("foo")
|
||||
api.On("GetChannelByName", "foo", "theteamid").Return(testChannel, nil).Once()
|
||||
channel, err = remote.GetChannelByName("foo", "theteamid")
|
||||
assert.Equal(t, testChannel, channel)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("GetDirectChannel", "user1", "user2").Return(testChannel, nil).Once()
|
||||
channel, err = remote.GetDirectChannel("user1", "user2")
|
||||
assert.Equal(t, testChannel, channel)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("GetGroupChannel", []string{"user1", "user2", "user3"}).Return(testChannel, nil).Once()
|
||||
channel, err = remote.GetGroupChannel([]string{"user1", "user2", "user3"})
|
||||
assert.Equal(t, testChannel, channel)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("UpdateChannel", mock.AnythingOfType("*model.Channel")).Return(func(c *model.Channel) (*model.Channel, *model.AppError) {
|
||||
return c, nil
|
||||
}).Once()
|
||||
channel, err = remote.UpdateChannel(testChannel)
|
||||
assert.Equal(t, testChannel, channel)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("CreateUser", mock.AnythingOfType("*model.User")).Return(func(u *model.User) (*model.User, *model.AppError) {
|
||||
u.Id = "theuserid"
|
||||
return u, nil
|
||||
}).Once()
|
||||
user, err := remote.CreateUser(testUser)
|
||||
assert.Equal(t, "theuserid", user.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("DeleteUser", "theuserid").Return(nil).Once()
|
||||
assert.Nil(t, remote.DeleteUser("theuserid"))
|
||||
|
||||
api.On("GetUser", "theuserid").Return(testUser, nil).Once()
|
||||
user, err = remote.GetUser("theuserid")
|
||||
assert.Equal(t, testUser, user)
|
||||
assert.Nil(t, err)
|
||||
|
||||
team, err := remote.GetTeamByName("foo")
|
||||
api.On("GetUserByEmail", "foo@foo").Return(testUser, nil).Once()
|
||||
user, err = remote.GetUserByEmail("foo@foo")
|
||||
assert.Equal(t, testUser, user)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("GetUserByUsername", "foo").Return(testUser, nil).Once()
|
||||
user, err = remote.GetUserByUsername("foo")
|
||||
assert.Equal(t, testUser, user)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("UpdateUser", mock.AnythingOfType("*model.User")).Return(func(u *model.User) (*model.User, *model.AppError) {
|
||||
return u, nil
|
||||
}).Once()
|
||||
user, err = remote.UpdateUser(testUser)
|
||||
assert.Equal(t, testUser, user)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("CreateTeam", mock.AnythingOfType("*model.Team")).Return(func(t *model.Team) (*model.Team, *model.AppError) {
|
||||
t.Id = "theteamid"
|
||||
return t, nil
|
||||
}).Once()
|
||||
team, err := remote.CreateTeam(testTeam)
|
||||
assert.Equal(t, "theteamid", team.Id)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("DeleteTeam", "theteamid").Return(nil).Once()
|
||||
assert.Nil(t, remote.DeleteTeam("theteamid"))
|
||||
|
||||
api.On("GetTeam", "theteamid").Return(testTeam, nil).Once()
|
||||
team, err = remote.GetTeam("theteamid")
|
||||
assert.Equal(t, testTeam, team)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("GetTeamByName", "foo").Return(testTeam, nil).Once()
|
||||
team, err = remote.GetTeamByName("foo")
|
||||
assert.Equal(t, testTeam, team)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("GetTeamByName", "notateam").Return(nil, teamNotFoundError).Once()
|
||||
team, err = remote.GetTeamByName("notateam")
|
||||
assert.Nil(t, team)
|
||||
assert.Equal(t, teamNotFoundError, err)
|
||||
|
||||
api.On("UpdateTeam", mock.AnythingOfType("*model.Team")).Return(func(t *model.Team) (*model.Team, *model.AppError) {
|
||||
return t, nil
|
||||
}).Once()
|
||||
team, err = remote.UpdateTeam(testTeam)
|
||||
assert.Equal(t, testTeam, team)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("CreatePost", mock.AnythingOfType("*model.Post")).Return(func(p *model.Post) (*model.Post, *model.AppError) {
|
||||
p.Id = "thepostid"
|
||||
return p, nil
|
||||
}).Once()
|
||||
post, err := remote.CreatePost(testPost)
|
||||
assert.NotEmpty(t, post.Id)
|
||||
assert.Equal(t, testPost.Message, post.Message)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("DeletePost", "thepostid").Return(nil).Once()
|
||||
assert.Nil(t, remote.DeletePost("thepostid"))
|
||||
|
||||
api.On("GetPost", "thepostid").Return(testPost, nil).Once()
|
||||
post, err = remote.GetPost("thepostid")
|
||||
assert.Equal(t, testPost, post)
|
||||
assert.Nil(t, err)
|
||||
|
||||
api.On("UpdatePost", mock.AnythingOfType("*model.Post")).Return(func(p *model.Post) (*model.Post, *model.AppError) {
|
||||
return p, nil
|
||||
}).Once()
|
||||
post, err = remote.UpdatePost(testPost)
|
||||
assert.Equal(t, testPost, post)
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user