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 удалений

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

@@ -76,6 +76,60 @@ func TestCreatePost(t *testing.T) {
t.Fatal("create at should not match")
}
t.Run("with file uploaded by same user", func(t *testing.T) {
fileResp, subResponse := Client.UploadFile([]byte("data"), th.BasicChannel.Id, "test")
CheckNoError(t, subResponse)
fileId := fileResp.FileInfos[0].Id
postWithFiles, subResponse := Client.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id,
Message: "with files",
FileIds: model.StringArray{fileId},
})
CheckNoError(t, subResponse)
assert.Equal(t, model.StringArray{fileId}, postWithFiles.FileIds)
actualPostWithFiles, subResponse := Client.GetPost(postWithFiles.Id, "")
CheckNoError(t, subResponse)
assert.Equal(t, model.StringArray{fileId}, actualPostWithFiles.FileIds)
})
t.Run("with file uploaded by different user", func(t *testing.T) {
fileResp, subResponse := th.SystemAdminClient.UploadFile([]byte("data"), th.BasicChannel.Id, "test")
CheckNoError(t, subResponse)
fileId := fileResp.FileInfos[0].Id
postWithFiles, subResponse := Client.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id,
Message: "with files",
FileIds: model.StringArray{fileId},
})
CheckNoError(t, subResponse)
assert.Empty(t, postWithFiles.FileIds)
actualPostWithFiles, subResponse := Client.GetPost(postWithFiles.Id, "")
CheckNoError(t, subResponse)
assert.Empty(t, actualPostWithFiles.FileIds)
})
t.Run("with file uploaded by nouser", func(t *testing.T) {
fileInfo, err := th.App.UploadFile([]byte("data"), th.BasicChannel.Id, "test")
require.Nil(t, err)
fileId := fileInfo.Id
postWithFiles, subResponse := Client.CreatePost(&model.Post{
ChannelId: th.BasicChannel.Id,
Message: "with files",
FileIds: model.StringArray{fileId},
})
CheckNoError(t, subResponse)
assert.Equal(t, model.StringArray{fileId}, postWithFiles.FileIds)
actualPostWithFiles, subResponse := Client.GetPost(postWithFiles.Id, "")
CheckNoError(t, subResponse)
assert.Equal(t, model.StringArray{fileId}, actualPostWithFiles.FileIds)
})
post.RootId = ""
post.ParentId = ""
post.Type = model.POST_SYSTEM_GENERIC