MM-2954 - Add a separate post type for /me messages and update formatting (#11082)
* MM-2954 * Added new const post type for /me commands * Modified me command to return response text without *__* wrapper * Modified unit test for MeCommand to reflect changes * Added unit test for the me command provider * * Reverted change to text property in me command response * Added original message in me command response props * Updated unit tests * gofmt changes
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
a760f32526
Коммит
66993e1fae
@@ -350,9 +350,16 @@ func TestMeCommand(t *testing.T) {
|
||||
if len(p1.Order) != 2 {
|
||||
t.Fatal("Command failed to send")
|
||||
} else {
|
||||
if p1.Posts[p1.Order[0]].Message != `*hello*` {
|
||||
t.Log(p1.Posts[p1.Order[0]].Message)
|
||||
t.Fatal("invalid shrug response")
|
||||
pt := p1.Posts[p1.Order[0]].Type
|
||||
if pt != model.POST_ME {
|
||||
t.Log(pt)
|
||||
t.Fatalf("invalid post type, got '%s', wanted '%s'", pt, model.POST_ME)
|
||||
}
|
||||
msg := p1.Posts[p1.Order[0]].Message
|
||||
want := "*hello*"
|
||||
if msg != want {
|
||||
t.Log(msg)
|
||||
t.Fatalf("invalid me response message, got '%s', wanted '%s'", msg, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,5 +34,12 @@ func (me *MeProvider) GetCommand(a *App, T goi18n.TranslateFunc) *model.Command
|
||||
}
|
||||
|
||||
func (me *MeProvider) DoCommand(a *App, args *model.CommandArgs, message string) *model.CommandResponse {
|
||||
return &model.CommandResponse{ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, Text: "*" + message + "*"}
|
||||
return &model.CommandResponse{
|
||||
ResponseType: model.COMMAND_RESPONSE_TYPE_IN_CHANNEL,
|
||||
Type: model.POST_ME,
|
||||
Text: "*" + message + "*",
|
||||
Props: model.StringInterface{
|
||||
"message": message,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
27
app/command_me_test.go
Обычный файл
27
app/command_me_test.go
Обычный файл
@@ -0,0 +1,27 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestMeProviderDoCommand(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
mp := MeProvider{}
|
||||
|
||||
msg := "hello"
|
||||
|
||||
resp := mp.DoCommand(th.App, &model.CommandArgs{}, msg)
|
||||
|
||||
assert.Equal(t, model.COMMAND_RESPONSE_TYPE_IN_CHANNEL, resp.ResponseType)
|
||||
assert.Equal(t, model.POST_ME, resp.Type)
|
||||
assert.Equal(t, "*"+msg+"*", resp.Text)
|
||||
assert.Equal(t, model.StringInterface{
|
||||
"message": msg,
|
||||
}, resp.Props)
|
||||
}
|
||||
@@ -48,6 +48,7 @@ const (
|
||||
POST_PROPS_MAX_RUNES = 8000
|
||||
POST_PROPS_MAX_USER_RUNES = POST_PROPS_MAX_RUNES - 400 // Leave some room for system / pre-save modifications
|
||||
POST_CUSTOM_TYPE_PREFIX = "custom_"
|
||||
POST_ME = "me"
|
||||
PROPS_ADD_CHANNEL_MEMBER = "add_channel_member"
|
||||
POST_PROPS_ADDED_USER_ID = "addedUserId"
|
||||
POST_PROPS_DELETE_BY = "deleteBy"
|
||||
@@ -236,6 +237,7 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
|
||||
POST_CONVERT_CHANNEL,
|
||||
POST_CHANNEL_DELETED,
|
||||
POST_CHANGE_CHANNEL_PRIVACY,
|
||||
POST_ME,
|
||||
POST_ADD_BOT_TEAMS_CHANNELS:
|
||||
default:
|
||||
if !strings.HasPrefix(o.Type, POST_CUSTOM_TYPE_PREFIX) {
|
||||
|
||||
Ссылка в новой задаче
Block a user