PluginAPI: add ability to retrieve users by ids (#26936)

* pluginapi: ability to retrieve users by ids

* fix test
Этот коммит содержится в:
Julien Tant
2024-05-15 07:06:40 -07:00
коммит произвёл GitHub
родитель 0911e4dee7
Коммит e96db725ea
8 изменённых файлов: 171 добавлений и 0 удалений

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

@@ -246,6 +246,10 @@ func (api *PluginAPI) GetUsers(options *model.UserGetOptions) ([]*model.User, *m
return api.app.GetUsersFromProfiles(options)
}
func (api *PluginAPI) GetUsersByIds(usersID []string) ([]*model.User, *model.AppError) {
return api.app.GetUsers(usersID)
}
func (api *PluginAPI) GetUser(userID string) (*model.User, *model.AppError) {
return api.app.GetUser(userID)
}

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

@@ -431,6 +431,61 @@ func TestPluginAPIGetUsers(t *testing.T) {
}
}
func TestPluginAPIGetUsersByIds(t *testing.T) {
th := Setup(t).DeleteBots()
defer th.TearDown()
api := th.SetupPluginAPI()
user1, err := th.App.CreateUser(th.Context, &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(th.Context, user1)
user2, err := th.App.CreateUser(th.Context, &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(th.Context, user2)
user3, err := th.App.CreateUser(th.Context, &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(th.Context, user3)
testCases := []struct {
Description string
requestedIDs []string
}{
{
"no users",
[]string{},
},
{
"getting 1 and 3",
[]string{user1.Id, user3.Id},
},
}
for _, testCase := range testCases {
t.Run(testCase.Description, func(t *testing.T) {
users, err := api.GetUsersByIds(testCase.requestedIDs)
assert.Nil(t, err)
assert.Equal(t, len(testCase.requestedIDs), len(users))
for _, user := range users {
assert.Contains(t, testCase.requestedIDs, user.Id)
}
})
}
}
func TestPluginAPIGetUsersInTeam(t *testing.T) {
th := Setup(t)
defer th.TearDown()