summaryrefslogtreecommitdiffstats
path: root/app/import_functions_test.go
diff options
context:
space:
mode:
authorPradeep Murugesan <pradeepmurugesan@outlook.com>2018-08-29 14:27:44 +0200
committerCarlos Tadeu Panato Junior <ctadeu@gmail.com>2018-08-29 14:27:44 +0200
commit7a3cf112c526cf8832d5a044ac590fb6c7ff8686 (patch)
treea57e962f4f6e37c442110b1a0484375f120897dd /app/import_functions_test.go
parentc2676d964e0706c75e884af714047e9c376ac698 (diff)
downloadchat-7a3cf112c526cf8832d5a044ac590fb6c7ff8686.tar.gz
chat-7a3cf112c526cf8832d5a044ac590fb6c7ff8686.tar.bz2
chat-7a3cf112c526cf8832d5a044ac590fb6c7ff8686.zip
9304 added the attachments import to direct post (#9308)
Diffstat (limited to 'app/import_functions_test.go')
-rw-r--r--app/import_functions_test.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/app/import_functions_test.go b/app/import_functions_test.go
index fd8ae462e..10b1d5587 100644
--- a/app/import_functions_test.go
+++ b/app/import_functions_test.go
@@ -2553,3 +2553,54 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
AssertFileIdsInPost(attachments, th, t)
}
+
+func TestImportDirectPostWithAttachments(t *testing.T) {
+
+ th := Setup()
+ defer th.TearDown()
+
+ testsDir, _ := utils.FindDir("tests")
+ testImage := filepath.Join(testsDir, "test.png")
+
+ // Create a user.
+ username := model.NewId()
+ th.App.ImportUser(&UserImportData{
+ Username: &username,
+ Email: ptrStr(model.NewId() + "@example.com"),
+ }, false)
+ user1, err := th.App.GetUserByUsername(username)
+ if err != nil {
+ t.Fatalf("Failed to get user1 from database.")
+ }
+
+ username2 := model.NewId()
+ th.App.ImportUser(&UserImportData{
+ Username: &username2,
+ Email: ptrStr(model.NewId() + "@example.com"),
+ }, false)
+
+ user2, err := th.App.GetUserByUsername(username2)
+ if err != nil {
+ t.Fatalf("Failed to get user2 from database.")
+ }
+
+ directImportData := &DirectPostImportData{
+ ChannelMembers: &[]string{
+ user1.Username,
+ user2.Username,
+ },
+ User: &user1.Username,
+ Message: ptrStr("Direct message"),
+ CreateAt: ptrInt64(model.GetMillis()),
+ Attachments: &[]AttachmentImportData{{Path: &testImage}},
+ }
+
+ if err := th.App.ImportDirectPost(directImportData, false); err != nil {
+ t.Fatalf("Expected success.")
+ }
+
+ attachments := GetAttachments(user1.Id, th, t)
+ assert.Equal(t, len(attachments), 1)
+ assert.Contains(t, attachments[0].Path, "noteam")
+ AssertFileIdsInPost(attachments, th, t)
+}