[MM-30978] avoid parsing nil PostAction in SlackAttachments (#16556)
* avoid parsing nil PostAction in SlackAttachments * reflect review comments * improve tests Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c54b262351
Коммит
bd5616557d
@@ -884,3 +884,48 @@ func TestSearchParameterFromJson(t *testing.T) {
|
||||
require.Equal(t, "test", *params.Terms)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPostAttachments(t *testing.T) {
|
||||
p := &Post{
|
||||
Props: map[string]interface{}{
|
||||
"attachments": []byte(`[{
|
||||
"actions" : {null}
|
||||
}]
|
||||
`),
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("empty actions", func(t *testing.T) {
|
||||
p.Props["attachments"] = []interface{}{
|
||||
map[string]interface{}{"actions": []interface{}{}},
|
||||
}
|
||||
attachments := p.Attachments()
|
||||
require.Empty(t, attachments[0].Actions)
|
||||
})
|
||||
|
||||
t.Run("a couple of actions", func(t *testing.T) {
|
||||
p.Props["attachments"] = []interface{}{
|
||||
map[string]interface{}{"actions": []interface{}{
|
||||
map[string]interface{}{"id": "test1"}, map[string]interface{}{"id": "test2"}},
|
||||
},
|
||||
}
|
||||
|
||||
attachments := p.Attachments()
|
||||
require.Len(t, attachments[0].Actions, 2)
|
||||
require.Equal(t, attachments[0].Actions[0].Id, "test1")
|
||||
require.Equal(t, attachments[0].Actions[1].Id, "test2")
|
||||
})
|
||||
|
||||
t.Run("should ignore null actions", func(t *testing.T) {
|
||||
p.Props["attachments"] = []interface{}{
|
||||
map[string]interface{}{"actions": []interface{}{
|
||||
map[string]interface{}{"id": "test1"}, nil, map[string]interface{}{"id": "test2"}, nil, nil},
|
||||
},
|
||||
}
|
||||
|
||||
attachments := p.Attachments()
|
||||
require.Len(t, attachments[0].Actions, 2)
|
||||
require.Equal(t, attachments[0].Actions[0].Id, "test1")
|
||||
require.Equal(t, attachments[0].Actions[1].Id, "test2")
|
||||
})
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user