PLT-7599: webhook post splitting (#7707)
* webhook post splitting * style fix * update old webhook test
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
61b023f5df
Коммит
9c0575ce6e
@@ -4,8 +4,12 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -50,3 +54,95 @@ func TestCreateWebhookPost(t *testing.T) {
|
||||
t.Fatal("should have failed - bad post type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplitWebhookPost(t *testing.T) {
|
||||
type TestCase struct {
|
||||
Post *model.Post
|
||||
Expected []*model.Post
|
||||
}
|
||||
|
||||
for name, tc := range map[string]TestCase{
|
||||
"LongPost": {
|
||||
Post: &model.Post{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES*3/2),
|
||||
},
|
||||
Expected: []*model.Post{
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES),
|
||||
},
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES/2),
|
||||
},
|
||||
},
|
||||
},
|
||||
"LongPostAndMultipleAttachments": {
|
||||
Post: &model.Post{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES*3/2),
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", 1000),
|
||||
},
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", 2000),
|
||||
},
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", model.POST_PROPS_MAX_USER_RUNES-1000),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Expected: []*model.Post{
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES),
|
||||
},
|
||||
{
|
||||
Message: strings.Repeat("本", model.POST_MESSAGE_MAX_RUNES/2),
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", 1000),
|
||||
},
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", 2000),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
&model.SlackAttachment{
|
||||
Text: strings.Repeat("本", model.POST_PROPS_MAX_USER_RUNES-1000),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"UnsplittableProps": {
|
||||
Post: &model.Post{
|
||||
Message: "foo",
|
||||
Props: map[string]interface{}{
|
||||
"foo": strings.Repeat("x", model.POST_PROPS_MAX_USER_RUNES*2),
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
splits, err := SplitWebhookPost(tc.Post)
|
||||
if tc.Expected == nil {
|
||||
require.NotNil(t, err)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
}
|
||||
assert.Equal(t, len(tc.Expected), len(splits))
|
||||
for i, split := range splits {
|
||||
if i < len(tc.Expected) {
|
||||
assert.Equal(t, tc.Expected[i].Message, split.Message)
|
||||
assert.Equal(t, tc.Expected[i].Props["attachments"], split.Props["attachments"])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user