From 7a3cf112c526cf8832d5a044ac590fb6c7ff8686 Mon Sep 17 00:00:00 2001 From: Pradeep Murugesan Date: Wed, 29 Aug 2018 14:27:44 +0200 Subject: 9304 added the attachments import to direct post (#9308) --- app/import_functions_test.go | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'app/import_functions_test.go') 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) +} -- cgit v1.2.3-1-g7c22