MM-37721: Add prop for post preview before saving record. (#18361)

* MM-37721: Add prop for post preview before saving record.

* MM-37721: Test fix.

* MM-37721: Adds test.

* MM-37721: Fixes vet.

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Martin Kraft
2021-09-16 13:54:38 -04:00
коммит произвёл GitHub
родитель f9bd7cce8e
Коммит acec8db7c5
2 изменённых файлов: 47 добавлений и 8 удалений

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

@@ -427,17 +427,17 @@ func TestPostChannelMentions(t *testing.T) {
CreateAt: 0,
}
result, err := th.App.CreatePostAsUser(th.Context, post, "", true)
post, err = th.App.CreatePostAsUser(th.Context, post, "", true)
require.Nil(t, err)
assert.Equal(t, map[string]interface{}{
"mention-test": map[string]interface{}{
"display_name": "Mention Test",
"team_name": th.BasicTeam.Name,
},
}, result.GetProp("channel_mentions"))
}, post.GetProp("channel_mentions"))
post.Message = fmt.Sprintf("goodbye, ~%v!", channelToMention.Name)
result, err = th.App.UpdatePost(th.Context, post, false)
result, err := th.App.UpdatePost(th.Context, post, false)
require.Nil(t, err)
assert.Equal(t, map[string]interface{}{
"mention-test": map[string]interface{}{
@@ -786,6 +786,44 @@ func TestCreatePost(t *testing.T) {
assert.Equal(t, previewPost.GetProps(), model.StringInterface{"previewed_post": referencedPost.Id})
})
t.Run("creates a single record for a permalink preview post", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
channelForPreview := th.CreateChannel(th.BasicTeam)
referencedPost := &model.Post{
ChannelId: th.BasicChannel.Id,
Message: "hello world",
UserId: th.BasicUser.Id,
}
referencedPost, err := th.App.CreatePost(th.Context, referencedPost, th.BasicChannel, false, false)
require.Nil(t, err)
th.App.UpdateConfig(func(cfg *model.Config) {
*cfg.ServiceSettings.SiteURL = "http://foobar.com"
*cfg.ServiceSettings.EnablePermalinkPreviews = true
})
permalink := fmt.Sprintf("%s/%s/pl/%s", *th.App.Config().ServiceSettings.SiteURL, th.BasicTeam.Name, referencedPost.Id)
previewPost := &model.Post{
ChannelId: channelForPreview.Id,
Message: permalink,
UserId: th.BasicUser.Id,
}
previewPost, err = th.App.CreatePost(th.Context, previewPost, channelForPreview, false, false)
require.Nil(t, err)
sqlStore := th.GetSqlStore()
sql := fmt.Sprintf("select count(*) from Posts where Id = '%[1]s' or OriginalId = '%[1]s';", previewPost.Id)
val, err2 := sqlStore.GetMaster().SelectInt(sql)
require.NoError(t, err2)
require.EqualValues(t, int64(1), val)
})
}
func TestPatchPost(t *testing.T) {