From bdccbfa517ae59f7dbd5627834686134960799b2 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 4 Sep 2015 12:53:17 -0700 Subject: [PATCH] fix(draft): fix forwarding message with files and add spec --- spec-nylas/stores/draft-store-spec.coffee | 26 +++++++++++++++++++++++ src/flux/stores/draft-store.coffee | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/spec-nylas/stores/draft-store-spec.coffee b/spec-nylas/stores/draft-store-spec.coffee index b071e65f0..eaa793b65 100644 --- a/spec-nylas/stores/draft-store-spec.coffee +++ b/spec-nylas/stores/draft-store-spec.coffee @@ -1,3 +1,4 @@ +File = require '../../src/flux/models/file' Thread = require '../../src/flux/models/thread' Message = require '../../src/flux/models/message' Contact = require '../../src/flux/models/contact' @@ -21,6 +22,7 @@ msgWithReplyTo = null msgWithReplyToDuplicates = null messageWithStyleTags = null fakeMessages = null +fakeMessageWithFiles = null class TestExtension extends DraftStoreExtension @prepareNewDraft: (draft) -> @@ -68,6 +70,18 @@ describe "DraftStore", -> subject: 'Re: Fake Subject' date: new Date(1415814587) + fakeMessageWithFiles = new Message + id: 'fake-message-with-files' + to: [new Contact(email: 'ben@nylas.com'), new Contact(email: 'evan@nylas.com')] + cc: [new Contact(email: 'mg@nylas.com'), new Contact(email: AccountStore.current().me().email)] + bcc: [new Contact(email: 'recruiting@nylas.com')] + from: [new Contact(email: 'customer@example.com', name: 'Customer')] + files: [new File(filename: "test.jpg"), new File(filename: "test.pdj")] + threadId: 'fake-thread-id' + body: 'Fake Message 1' + subject: 'Fake Subject' + date: new Date(1415814587) + msgFromMe = new Message id: 'fake-message-3' to: [new Contact(email: '1@1.com'), new Contact(email: '2@2.com')] @@ -118,6 +132,7 @@ describe "DraftStore", -> 'fake-message-3': msgFromMe 'fake-message-2': fakeMessage2 'fake-message-reply-to': msgWithReplyTo + 'fake-message-with-files': fakeMessageWithFiles 'fake-message-reply-to-duplicates': msgWithReplyToDuplicates 'message-with-style-tags': messageWithStyleTags @@ -275,6 +290,17 @@ describe "DraftStore", -> expect(@model.cc).toEqual(msgFromMe.cc) expect(@model.bcc.length).toBe 0 + describe "forwarding with attachments", -> + it "should include the attached files", -> + runs -> + DraftStore._onComposeForward({threadId: fakeThread.id, messageId: fakeMessageWithFiles.id}) + waitsFor -> + DatabaseStore.persistModel.callCount > 0 + runs -> + @model = DatabaseStore.persistModel.mostRecentCall.args[0] + expect(@model.files.length).toBe 2 + expect(@model.files[0].filename).toBe "test.jpg" + describe "onComposeForward", -> beforeEach -> runs -> diff --git a/src/flux/stores/draft-store.coffee b/src/flux/stores/draft-store.coffee index 3e01ab86d..bf898f58a 100644 --- a/src/flux/stores/draft-store.coffee +++ b/src/flux/stores/draft-store.coffee @@ -291,7 +291,7 @@ class DraftStore if msg.files?.length > 0 attributes.files ?= [] - attributes.files = attributes.files.concat(forwardMessage.files) + attributes.files = attributes.files.concat(msg.files) attributes.subject = subjectWithPrefix(msg.subject, 'Fwd:') delete attributes.forwardedMessage