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()
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
8cfca681b0
Коммит
0a73690537
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user