summaryrefslogtreecommitdiffstats
path: root/app/file_test.go
diff options
context:
space:
mode:
authordmitrysamuylovpharo <dsamuylov@pharo.com>2018-08-02 10:37:31 -0400
committerHarrison Healey <harrisonmhealey@gmail.com>2018-08-02 10:37:31 -0400
commit7a731d2bd162419086f3aeec98ec41dfcaa16696 (patch)
treefb2dcfd52b5ee074c2ce9e3fbacefc3156c5bc75 /app/file_test.go
parentb728b16f9083bf5c71e9c27ad074823e8e454b04 (diff)
downloadchat-7a731d2bd162419086f3aeec98ec41dfcaa16696.tar.gz
chat-7a731d2bd162419086f3aeec98ec41dfcaa16696.tar.bz2
chat-7a731d2bd162419086f3aeec98ec41dfcaa16696.zip
Feature/fileinfo create copy (#9198)
* Initial implementation of a CopyFileInfos function that creates new FileInfo objects copied from provided FileIds with the provided user as the creator and not linked to a post yet. This can subsequently be used to copy existing attachments from another post to attach to a new post without having to re-upload the actual files * added a unit test for the CopyFileInfos function * resolving pull request suggestions
Diffstat (limited to 'app/file_test.go')
-rw-r--r--app/file_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/file_test.go b/app/file_test.go
index 23750ad6e..c736328cf 100644
--- a/app/file_test.go
+++ b/app/file_test.go
@@ -161,3 +161,34 @@ func TestMigrateFilenamesToFileInfos(t *testing.T) {
infos = th.App.MigrateFilenamesToFileInfos(rpost)
assert.Equal(t, 1, len(infos))
}
+
+func TestCopyFileInfos(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ teamId := model.NewId()
+ channelId := model.NewId()
+ userId := model.NewId()
+ filename := "test"
+ data := []byte("abcd")
+
+ info1, err := th.App.DoUploadFile(time.Date(2007, 2, 4, 1, 2, 3, 4, time.Local), teamId, channelId, userId, filename, data)
+ require.Nil(t, err)
+ defer func() {
+ <-th.App.Srv.Store.FileInfo().PermanentDelete(info1.Id)
+ th.App.RemoveFile(info1.Path)
+ }()
+
+ infoIds, err := th.App.CopyFileInfos(userId, []string{info1.Id})
+ require.Nil(t, err)
+
+ info2, err := th.App.GetFileInfo(infoIds[0])
+ require.Nil(t, err)
+ defer func() {
+ <-th.App.Srv.Store.FileInfo().PermanentDelete(info2.Id)
+ th.App.RemoveFile(info2.Path)
+ }()
+
+ assert.NotEqual(t, info1.Id, info2.Id, "should not be equal")
+ assert.Equal(t, info2.PostId, "", "should be empty string")
+}