MM-17438: allow attaching nouser files to posts (#11837)

* tweak AttachToPost formatting

* test attaching files uploaded by nouser

* MM-17438: allow attaching nouser files to posts
Этот коммит содержится в:
Jesse Hallam
2019-08-12 18:35:46 -03:00
коммит произвёл GitHub
родитель e4bb8cd887
Коммит 9bb36614a6
4 изменённых файлов: 138 добавлений и 15 удалений

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

@@ -319,6 +319,7 @@ func TestPluginAPIGetFile(t *testing.T) {
require.NotNil(t, err)
require.Nil(t, data)
}
func TestPluginAPISavePluginConfig(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
@@ -1244,3 +1245,37 @@ func TestPluginCreateBot(t *testing.T) {
require.NotNil(t, err)
}
func TestPluginCreatePostWithUploadedFile(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
api := th.SetupPluginAPI()
data := []byte("Hello World")
channelId := th.BasicChannel.Id
filename := "testGetFile"
fileInfo, err := api.UploadFile(data, channelId, filename)
require.Nil(t, err)
defer func() {
th.App.Srv.Store.FileInfo().PermanentDelete(fileInfo.Id)
th.App.RemoveFile(fileInfo.Path)
}()
actualData, err := api.GetFile(fileInfo.Id)
require.Nil(t, err)
assert.Equal(t, data, actualData)
userId := th.BasicUser.Id
post, err := api.CreatePost(&model.Post{
Message: "test",
UserId: userId,
ChannelId: channelId,
FileIds: model.StringArray{fileInfo.Id},
})
require.Nil(t, err)
assert.Equal(t, model.StringArray{fileInfo.Id}, post.FileIds)
actualPost, err := api.GetPost(post.Id)
require.Nil(t, err)
assert.Equal(t, model.StringArray{fileInfo.Id}, actualPost.FileIds)
}