fix two page, perPage -> offset, limit mistranslations (#9904)

* fix two page, perPage -> offset, limit mistranslations

* add TestPluginAPIGetUsersInTeam
Этот коммит содержится в:
Jesse Hallam
2018-11-29 13:02:06 -05:00
коммит произвёл GitHub
родитель 8bbd99aea9
Коммит 6d9b4bc277
4 изменённых файлов: 139 добавлений и 14 удалений

Просмотреть файл

@@ -188,7 +188,7 @@ func (api *PluginAPI) GetUsersByUsernames(usernames []string) ([]*model.User, *m
}
func (api *PluginAPI) GetUsersInTeam(teamId string, page int, perPage int) ([]*model.User, *model.AppError) {
return api.app.GetUsersInTeam(teamId, page, perPage)
return api.app.GetUsersInTeam(teamId, page*perPage, perPage)
}
func (api *PluginAPI) UpdateUser(user *model.User) (*model.User, *model.AppError) {

Просмотреть файл

@@ -13,6 +13,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"
"github.com/mattermost/mattermost-server/model"
@@ -44,6 +45,115 @@ func setupPluginApiTest(t *testing.T, pluginCode string, pluginManifest string,
app.SetPluginsEnvironment(env)
}
func TestPluginAPIGetUsersInTeam(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
team1 := th.CreateTeam()
team2 := th.CreateTeam()
user1, err := th.App.CreateUser(&model.User{
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
Password: "password",
Username: "user1" + model.NewId(),
})
require.Nil(t, err)
defer th.App.PermanentDeleteUser(user1)
user2, err := th.App.CreateUser(&model.User{
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
Password: "password",
Username: "user2" + model.NewId(),
})
require.Nil(t, err)
defer th.App.PermanentDeleteUser(user2)
user3, err := th.App.CreateUser(&model.User{
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
Password: "password",
Username: "user3" + model.NewId(),
})
require.Nil(t, err)
defer th.App.PermanentDeleteUser(user3)
user4, err := th.App.CreateUser(&model.User{
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
Password: "password",
Username: "user4" + model.NewId(),
})
require.Nil(t, err)
defer th.App.PermanentDeleteUser(user4)
// Add all users to team 1
_, _, err = th.App.joinUserToTeam(team1, user1)
require.Nil(t, err)
_, _, err = th.App.joinUserToTeam(team1, user2)
require.Nil(t, err)
_, _, err = th.App.joinUserToTeam(team1, user3)
require.Nil(t, err)
_, _, err = th.App.joinUserToTeam(team1, user4)
require.Nil(t, err)
// Add only user3 and user4 to team 2
_, _, err = th.App.joinUserToTeam(team2, user3)
require.Nil(t, err)
_, _, err = th.App.joinUserToTeam(team2, user4)
require.Nil(t, err)
testCases := []struct {
Description string
TeamId string
Page int
PerPage int
ExpectedUsers []*model.User
}{
{
"unknown team",
model.NewId(),
0,
0,
[]*model.User{},
},
{
"team 1, page 0, perPage 10",
team1.Id,
0,
10,
[]*model.User{user1, user2, user3, user4},
},
{
"team 1, page 0, perPage 2",
team1.Id,
0,
2,
[]*model.User{user1, user2},
},
{
"team 1, page 1, perPage 2",
team1.Id,
1,
2,
[]*model.User{user3, user4},
},
{
"team 2, page 0, perPage 10",
team2.Id,
0,
10,
[]*model.User{user3, user4},
},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
users, err := api.GetUsersInTeam(testCase.TeamId, testCase.Page, testCase.PerPage)
assert.Nil(t, err)
assert.Equal(t, testCase.ExpectedUsers, users)
})
}
}
func TestPluginAPIUpdateUserStatus(t *testing.T) {
th := Setup().InitBasic()
defer th.TearDown()

Просмотреть файл

@@ -104,7 +104,7 @@ func (a *App) DeleteAllExpiredPluginKeys() *model.AppError {
}
func (a *App) ListPluginKeys(pluginId string, page, perPage int) ([]string, *model.AppError) {
result := <-a.Srv.Store.Plugin().List(pluginId, page, perPage)
result := <-a.Srv.Store.Plugin().List(pluginId, page*perPage, perPage)
if result.Err != nil {
mlog.Error("Failed to list plugin key values", mlog.Int("page", page), mlog.Int("perPage", perPage), mlog.Err(result.Err))

Просмотреть файл

@@ -34,6 +34,8 @@ func TestPluginKeyValueStore(t *testing.T) {
defer func() {
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key2"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key3"))
assert.Nil(t, th.App.DeletePluginKey(pluginId, "key4"))
}()
assert.Nil(t, th.App.SetPluginKey(pluginId, "key", []byte("test")))
@@ -78,36 +80,49 @@ func TestPluginKeyValueStore(t *testing.T) {
assert.Equal(t, kv.Value, ret)
// Test ListKeys
assert.Nil(t, th.App.SetPluginKey(pluginId, "key3", []byte("test3")))
assert.Nil(t, th.App.SetPluginKey(pluginId, "key4", []byte("test4")))
list, err := th.App.ListPluginKeys(pluginId, 0, 1)
assert.Nil(t, err)
assert.Equal(t, 1, len(list))
assert.Equal(t, "key", list[0])
assert.Equal(t, []string{"key"}, list)
list, err = th.App.ListPluginKeys(pluginId, 1, 1)
assert.Nil(t, err)
assert.Equal(t, 1, len(list))
assert.Equal(t, hashedKey2, list[0])
assert.Equal(t, []string{"key3"}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, 4)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, 2)
assert.Nil(t, err)
assert.Equal(t, []string{"key", "key3"}, list)
list, err = th.App.ListPluginKeys(pluginId, 1, 2)
assert.Nil(t, err)
assert.Equal(t, []string{"key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 2, 2)
assert.Nil(t, err)
assert.Equal(t, []string{}, list)
// List Keys bad input
list, err = th.App.ListPluginKeys(pluginId, 0, 0)
assert.Nil(t, err)
assert.Equal(t, 2, len(list))
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, 0, -1)
assert.Nil(t, err)
assert.Equal(t, 2, len(list))
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
list, err = th.App.ListPluginKeys(pluginId, -1, 1)
assert.Nil(t, err)
assert.Equal(t, 1, len(list))
assert.Equal(t, []string{"key"}, list)
list, err = th.App.ListPluginKeys(pluginId, -1, 0)
assert.Nil(t, err)
assert.Equal(t, 2, len(list))
list, err = th.App.ListPluginKeys(pluginId, 2, 2)
assert.Nil(t, err)
assert.Equal(t, 0, len(list))
assert.Equal(t, []string{"key", "key3", "key4", hashedKey2}, list)
}
func TestServePluginRequest(t *testing.T) {