[MM-34076] Add Plugin API User custom status (#17435)

* add missing client for custom user status

* add custom user status plugin api

* update based on feedback review

* add GetCustomStatus

* update interfaces
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2021-11-10 17:11:20 +01:00
коммит произвёл GitHub
родитель 0a3e7f4d55
Коммит bb5a74a42b
13 изменённых файлов: 290 добавлений и 4 удалений

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

@@ -494,6 +494,59 @@ func TestPluginAPIGetUsersInTeam(t *testing.T) {
}
}
func TestPluginAPIUserCustomStatus(t *testing.T) {
th := Setup(t)
defer th.TearDown()
api := th.SetupPluginAPI()
user1, err := th.App.CreateUser(th.Context, &model.User{
Email: strings.ToLower(model.NewId()) + "success+test@example.com",
Username: "user_" + model.NewId(),
Password: "password",
})
require.Nil(t, err)
defer th.App.PermanentDeleteUser(th.Context, user1)
custom := &model.CustomStatus{
Emoji: ":tada:",
Text: "honk",
}
err = api.UpdateUserCustomStatus(user1.Id, custom)
assert.Nil(t, err)
userCs, err := th.App.GetCustomStatus(user1.Id)
assert.Nil(t, err)
assert.Equal(t, custom, userCs)
custom.Text = ""
err = api.UpdateUserCustomStatus(user1.Id, custom)
assert.Nil(t, err)
userCs, err = th.App.GetCustomStatus(user1.Id)
assert.Nil(t, err)
assert.Equal(t, custom, userCs)
custom.Text = "honk"
custom.Emoji = ""
err = api.UpdateUserCustomStatus(user1.Id, custom)
assert.Nil(t, err)
userCs, err = th.App.GetCustomStatus(user1.Id)
assert.Nil(t, err)
assert.Equal(t, custom, userCs)
custom.Text = ""
err = api.UpdateUserCustomStatus(user1.Id, custom)
assert.NotNil(t, err)
assert.Equal(t, err.Error(), "SetCustomStatus: Failed to update the custom status. Please add either emoji or custom text status or both., ")
// Remove custom status
err = api.RemoveUserCustomStatus(user1.Id)
assert.Nil(t, err)
var csClear *model.CustomStatus
userCs, err = th.App.GetCustomStatus(user1.Id)
assert.Nil(t, err)
assert.Equal(t, csClear, userCs)
}
func TestPluginAPIGetFile(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
@@ -715,7 +768,6 @@ func TestPluginAPILoadPluginConfiguration(t *testing.T) {
]
}}`)
require.NoError(t, err)
}
func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
@@ -755,7 +807,6 @@ func TestPluginAPILoadPluginConfigurationDefaults(t *testing.T) {
}`)
require.NoError(t, err)
}
func TestPluginAPIGetPlugins(t *testing.T) {
@@ -1084,6 +1135,7 @@ func pluginAPIHookTest(t *testing.T, th *TestHelper, fileName string, id string,
if ret != "OK" {
return errors.New(ret)
}
return nil
}
@@ -1284,7 +1336,6 @@ func TestPluginCreateBot(t *testing.T) {
Description: "bot2",
})
require.NotNil(t, err)
}
func TestPluginCreatePostWithUploadedFile(t *testing.T) {
@@ -1748,6 +1799,7 @@ type MockSlashCommandProvider struct {
func (*MockSlashCommandProvider) GetTrigger() string {
return "mock"
}
func (*MockSlashCommandProvider) GetCommand(a *App, T i18n.TranslateFunc) *model.Command {
return &model.Command{
Trigger: "mock",
@@ -1757,6 +1809,7 @@ func (*MockSlashCommandProvider) GetCommand(a *App, T i18n.TranslateFunc) *model
DisplayName: "mock",
}
}
func (mscp *MockSlashCommandProvider) DoCommand(a *App, c *request.Context, args *model.CommandArgs, message string) *model.CommandResponse {
mscp.Args = args
mscp.Message = message
@@ -1920,7 +1973,6 @@ func TestPluginAPIUpdateCommand(t *testing.T) {
require.NoError(t, appErr)
require.Equal(t, "anothernewtriggeragain", newCmd4.Trigger)
require.Equal(t, team1.Id, newCmd4.TeamId)
}
func TestPluginAPIIsEnterpriseReady(t *testing.T) {