summaryrefslogtreecommitdiffstats
path: root/app/webhook_test.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-24 18:36:31 -0500
committerJoram Wilander <jwawilander@gmail.com>2017-10-24 19:36:31 -0400
commit9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae (patch)
tree635ba5631b382c1e69f9719c6131ce74428b69ed /app/webhook_test.go
parent61b023f5dfe796c7ba8183292853f01817016d14 (diff)
downloadchat-9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae.tar.gz
chat-9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae.tar.bz2
chat-9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae.zip
PLT-7599: webhook post splitting (#7707)
* webhook post splitting * style fix * update old webhook test
Diffstat (limited to 'app/webhook_test.go')
-rw-r--r--app/webhook_test.go96
1 files changed, 96 insertions, 0 deletions
diff --git a/app/webhook_test.go b/app/webhook_test.go
index d6293e2b7..8dc90b49b 100644
--- a/app/webhook_test.go
+++ b/app/webhook_test.go
@@ -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"])
+ }
+ }
+ })
+ }
+}