Remove *model.ChannelList from plugin API return parameter (#9844)

* Remove *model.ChannelList from plugin API return parametern

* Fix panic

* Add tests

* Changes as requested

* Fix panic in GetPublicChannelsForTeam()
This commit is contained in:
Hanzei
2018-11-20 14:50:34 +01:00
committed by Joram Wilander
parent 8cfca681b0
commit 0a73690537
5 changed files with 67 additions and 20 deletions

View File

@@ -262,6 +262,9 @@ func (api *PluginAPI) DeleteChannel(channelId string) *model.AppError {
func (api *PluginAPI) GetPublicChannelsForTeam(teamId string, page, perPage int) ([]*model.Channel, *model.AppError) {
channels, err := api.app.GetPublicChannelsForTeam(teamId, page*perPage, perPage)
if err != nil {
return nil, err
}
return *channels, err
}
@@ -277,8 +280,12 @@ func (api *PluginAPI) GetChannelByNameForTeamName(teamName, channelName string,
return api.app.GetChannelByNameForTeamName(channelName, teamName, includeDeleted)
}
func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
return api.app.GetChannelsForUser(teamId, userId, includeDeleted)
func (api *PluginAPI) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
channels, err := api.app.GetChannelsForUser(teamId, userId, includeDeleted)
if err != nil {
return nil, err
}
return *channels, err
}
func (api *PluginAPI) GetChannelStats(channelId string) (*model.ChannelStats, *model.AppError) {
@@ -301,8 +308,12 @@ func (api *PluginAPI) UpdateChannel(channel *model.Channel) (*model.Channel, *mo
return api.app.UpdateChannel(channel)
}
func (api *PluginAPI) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
return api.app.SearchChannels(teamId, term)
func (api *PluginAPI) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
channels, err := api.app.SearchChannels(teamId, term)
if err != nil {
return nil, err
}
return *channels, err
}
func (api *PluginAPI) AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError) {

View File

@@ -450,3 +450,39 @@ func TestPluginAPISetTeamIcon(t *testing.T) {
require.Nil(t, err2)
require.Equal(t, img2.At(2, 3), colorful)
}
func TestPluginAPISearchChannels(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
t.Run("all fine", func(t *testing.T) {
channels, err := api.SearchChannels(th.BasicTeam.Id, th.BasicChannel.Name)
assert.Nil(t, err)
assert.Len(t, channels, 1)
})
t.Run("invalid team id", func(t *testing.T) {
channels, err := api.SearchChannels("invalidid", th.BasicChannel.Name)
assert.Nil(t, err)
assert.Empty(t, channels)
})
}
func TestPluginAPIGetChannelsForTeamForUser(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
t.Run("all fine", func(t *testing.T) {
channels, err := api.GetChannelsForTeamForUser(th.BasicTeam.Id, th.BasicUser.Id, false)
assert.Nil(t, err)
assert.Len(t, channels, 3)
})
t.Run("invalid team id", func(t *testing.T) {
channels, err := api.GetChannelsForTeamForUser("invalidid", th.BasicUser.Id, false)
assert.NotNil(t, err)
assert.Empty(t, channels)
})
}

View File

@@ -178,7 +178,7 @@ type API interface {
// GetChannelsForTeamForUser gets a list of channels for given user ID in given team ID.
//
// Minimum server version: 5.6
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)
// GetChannelStats gets statistics for a channel.
//
@@ -197,7 +197,7 @@ type API interface {
// SearchChannels returns the channels on a team matching the provided search term.
//
// Minimum server version: 5.6
SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)
// AddChannelMember creates a channel membership for a user.
AddChannelMember(channelId, userId string) (*model.ChannelMember, *model.AppError)

View File

@@ -1778,11 +1778,11 @@ type Z_GetChannelsForTeamForUserArgs struct {
}
type Z_GetChannelsForTeamForUserReturns struct {
A *model.ChannelList
A []*model.Channel
B *model.AppError
}
func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
_args := &Z_GetChannelsForTeamForUserArgs{teamId, userId, includeDeleted}
_returns := &Z_GetChannelsForTeamForUserReturns{}
if err := g.client.Call("Plugin.GetChannelsForTeamForUser", _args, _returns); err != nil {
@@ -1793,7 +1793,7 @@ func (g *apiRPCClient) GetChannelsForTeamForUser(teamId, userId string, includeD
func (s *apiRPCServer) GetChannelsForTeamForUser(args *Z_GetChannelsForTeamForUserArgs, returns *Z_GetChannelsForTeamForUserReturns) error {
if hook, ok := s.impl.(interface {
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError)
GetChannelsForTeamForUser(teamId, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError)
}); ok {
returns.A, returns.B = hook.GetChannelsForTeamForUser(args.A, args.B, args.C)
} else {
@@ -1925,11 +1925,11 @@ type Z_SearchChannelsArgs struct {
}
type Z_SearchChannelsReturns struct {
A *model.ChannelList
A []*model.Channel
B *model.AppError
}
func (g *apiRPCClient) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
func (g *apiRPCClient) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
_args := &Z_SearchChannelsArgs{teamId, term}
_returns := &Z_SearchChannelsReturns{}
if err := g.client.Call("Plugin.SearchChannels", _args, _returns); err != nil {
@@ -1940,7 +1940,7 @@ func (g *apiRPCClient) SearchChannels(teamId string, term string) (*model.Channe
func (s *apiRPCServer) SearchChannels(args *Z_SearchChannelsArgs, returns *Z_SearchChannelsReturns) error {
if hook, ok := s.impl.(interface {
SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError)
SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError)
}); ok {
returns.A, returns.B = hook.SearchChannels(args.A, args.B)
} else {

View File

@@ -541,15 +541,15 @@ func (_m *API) GetChannelStats(channelId string) (*model.ChannelStats, *model.Ap
}
// GetChannelsForTeamForUser provides a mock function with given fields: teamId, userId, includeDeleted
func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDeleted bool) (*model.ChannelList, *model.AppError) {
func (_m *API) GetChannelsForTeamForUser(teamId string, userId string, includeDeleted bool) ([]*model.Channel, *model.AppError) {
ret := _m.Called(teamId, userId, includeDeleted)
var r0 *model.ChannelList
if rf, ok := ret.Get(0).(func(string, string, bool) *model.ChannelList); ok {
var r0 []*model.Channel
if rf, ok := ret.Get(0).(func(string, string, bool) []*model.Channel); ok {
r0 = rf(teamId, userId, includeDeleted)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.ChannelList)
r0 = ret.Get(0).([]*model.Channel)
}
}
@@ -1866,15 +1866,15 @@ func (_m *API) SavePluginConfig(pluginConfig map[string]interface{}) *model.AppE
}
// SearchChannels provides a mock function with given fields: teamId, term
func (_m *API) SearchChannels(teamId string, term string) (*model.ChannelList, *model.AppError) {
func (_m *API) SearchChannels(teamId string, term string) ([]*model.Channel, *model.AppError) {
ret := _m.Called(teamId, term)
var r0 *model.ChannelList
if rf, ok := ret.Get(0).(func(string, string) *model.ChannelList); ok {
var r0 []*model.Channel
if rf, ok := ret.Get(0).(func(string, string) []*model.Channel); ok {
r0 = rf(teamId, term)
} else {
if ret.Get(0) != nil {
r0 = ret.Get(0).(*model.ChannelList)
r0 = ret.Get(0).([]*model.Channel)
}
}