[MM-62427] Add message attachments validation (#30180)
* Add message attachments validation * Add props validation * Validate slack attachment fields * Update tests and library usage * Improve interactive dialog error for length checks * Allow predefined colors for slack attachments * Fix TestPostAction * Use const for data source * Add tests * Cleanup unused props * Add happy path tests * lint fixes * Add validation for PostActionOptions
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
5609489e86
Коммит
9b5d8d52bf
@@ -39,7 +39,7 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
assert.NotEmpty(th.t, poir.TeamName)
|
||||
assert.NotEmpty(th.t, poir.PostId)
|
||||
assert.NotEmpty(th.t, poir.TriggerId)
|
||||
assert.Equal(th.t, "button", poir.Type)
|
||||
assert.Equal(th.t, model.PostActionTypeButton, poir.Type)
|
||||
assert.Equal(th.t, "test-value", poir.Context["test-key"])
|
||||
_, err = w.Write([]byte("{}"))
|
||||
require.NoError(th.t, err)
|
||||
@@ -118,7 +118,7 @@ func TestPostActionCookies(t *testing.T) {
|
||||
CreateAt: model.GetMillis(),
|
||||
UpdateAt: model.GetMillis(),
|
||||
Props: map[string]any{
|
||||
"attachments": []*model.SlackAttachment{
|
||||
model.PostPropsAttachments: []*model.SlackAttachment{
|
||||
{
|
||||
Title: "some-title",
|
||||
TitleLink: "https://some-url.com",
|
||||
|
||||
@@ -1420,7 +1420,7 @@ func TestUpdatePost(t *testing.T) {
|
||||
ChannelId: channel.Id,
|
||||
Message: "zz" + model.NewId() + " update post 3",
|
||||
}
|
||||
up4.AddProp("attachments", []model.SlackAttachment{
|
||||
up4.AddProp(model.PostPropsAttachments, []model.SlackAttachment{
|
||||
{
|
||||
Text: "Hello World",
|
||||
},
|
||||
@@ -1772,12 +1772,12 @@ func TestPatchPost(t *testing.T) {
|
||||
Text: "Hello World",
|
||||
},
|
||||
}
|
||||
patch2.Props = &model.StringInterface{"attachments": attachments}
|
||||
patch2.Props = &model.StringInterface{model.PostPropsAttachments: attachments}
|
||||
|
||||
var rpost2 *model.Post
|
||||
rpost2, _, err = client.PatchPost(context.Background(), post.Id, patch2)
|
||||
require.NoError(t, err)
|
||||
assert.NotEmpty(t, rpost2.GetProp("attachments"))
|
||||
assert.NotEmpty(t, rpost2.GetProp(model.PostPropsAttachments))
|
||||
assert.NotEqual(t, rpost.EditAt, rpost2.EditAt)
|
||||
})
|
||||
|
||||
@@ -4682,7 +4682,7 @@ func TestGetPostStripActionIntegrations(t *testing.T) {
|
||||
ChannelId: th.BasicChannel.Id,
|
||||
Message: "with slack attachment action",
|
||||
}
|
||||
post.AddProp("attachments", []*model.SlackAttachment{
|
||||
post.AddProp(model.PostPropsAttachments, []*model.SlackAttachment{
|
||||
{
|
||||
Text: "Slack Attachment Text",
|
||||
Fields: []*model.SlackAttachmentField{
|
||||
@@ -4694,7 +4694,7 @@ func TestGetPostStripActionIntegrations(t *testing.T) {
|
||||
},
|
||||
Actions: []*model.PostAction{
|
||||
{
|
||||
Type: "button",
|
||||
Type: model.PostActionTypeButton,
|
||||
Name: "test-name",
|
||||
Integration: &model.PostActionIntegration{
|
||||
URL: "https://test.test/action",
|
||||
@@ -4713,7 +4713,7 @@ func TestGetPostStripActionIntegrations(t *testing.T) {
|
||||
|
||||
actualPost, _, err := client.GetPost(context.Background(), rpost.Id, "")
|
||||
require.NoError(t, err)
|
||||
attachments, _ := actualPost.Props["attachments"].([]any)
|
||||
attachments, _ := actualPost.Props[model.PostPropsAttachments].([]any)
|
||||
require.Equal(t, 1, len(attachments))
|
||||
att, _ := attachments[0].(map[string]any)
|
||||
require.NotNil(t, att)
|
||||
|
||||
Ссылка в новой задаче
Block a user