From b849793a72deaacd5c9dff49995582a337ade8c6 Mon Sep 17 00:00:00 2001 From: Halla Moore Date: Tue, 21 Mar 2017 14:20:11 -0700 Subject: [PATCH] [client-app] Fix DraftFactory specs Summary: Using `await` instead of `advanceClock()` fixes all the things! Test Plan: Ran the spec file Reviewers: evan, juan Reviewed By: juan Differential Revision: https://phab.nylas.com/D4248 --- .../spec/stores/draft-factory-spec.es6 | 63 ++++++++++--------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/packages/client-app/spec/stores/draft-factory-spec.es6 b/packages/client-app/spec/stores/draft-factory-spec.es6 index a4734dd71..ee9f57f97 100644 --- a/packages/client-app/spec/stores/draft-factory-spec.es6 +++ b/packages/client-app/spec/stores/draft-factory-spec.es6 @@ -25,7 +25,7 @@ let msgWithReplyToDuplicates = null; let msgWithReplyToFromMe = null; let account = null; -xdescribe('DraftFactory', function draftFactory() { +describe('DraftFactory', function draftFactory() { beforeEach(() => { // Out of the scope of these specs spyOn(InlineStyleTransformer, 'run').andCallFake((input) => Promise.resolve(input)); @@ -429,55 +429,60 @@ xdescribe('DraftFactory', function draftFactory() { }); describe("when reply-all is passed", () => { - it("should add missing participants", () => { + it("should add missing participants", async () => { this.existingDraft.to = fakeMessage1.participantsForReply().to; this.existingDraft.cc = fakeMessage1.participantsForReply().cc; - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply-all', behavior: 'prefer-existing'}) - advanceClock(); - advanceClock(); - - const {to, cc} = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const {to, cc} = await DraftFactory.createOrUpdateDraftForReply({ + thread: fakeThread, + message: fakeMessage1, + type: 'reply-all', + behavior: 'prefer-existing', + }) this.expectContactsEqual(to, fakeMessage1.participantsForReplyAll().to); this.expectContactsEqual(cc, fakeMessage1.participantsForReplyAll().cc); }); - it("should not blow away other participants who have been added to the draft", () => { + it("should not blow away other participants who have been added to the draft", async () => { const randomA = new Contact({email: 'other-guy-a@gmail.com'}); const randomB = new Contact({email: 'other-guy-b@gmail.com'}); this.existingDraft.to = fakeMessage1.participantsForReply().to.concat([randomA]); this.existingDraft.cc = fakeMessage1.participantsForReply().cc.concat([randomB]); - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply-all', behavior: 'prefer-existing'}) - advanceClock(); - advanceClock(); - - const {to, cc} = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const {to, cc} = await DraftFactory.createOrUpdateDraftForReply({ + thread: fakeThread, + message: fakeMessage1, + type: 'reply-all', + behavior: 'prefer-existing', + }) this.expectContactsEqual(to, fakeMessage1.participantsForReplyAll().to.concat([randomA])); this.expectContactsEqual(cc, fakeMessage1.participantsForReplyAll().cc.concat([randomB])); }); }); describe("when reply is passed", () => { - it("should remove participants present in the reply-all participant set and not in the reply set", () => { + it("should remove participants present in the reply-all participant set and not in the reply set", async () => { this.existingDraft.to = fakeMessage1.participantsForReplyAll().to; this.existingDraft.cc = fakeMessage1.participantsForReplyAll().cc; - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply', behavior: 'prefer-existing'}) - advanceClock(); - advanceClock(); - - const {to, cc} = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const {to, cc} = await DraftFactory.createOrUpdateDraftForReply({ + thread: fakeThread, + message: fakeMessage1, + type: 'reply', + behavior: 'prefer-existing', + }) this.expectContactsEqual(to, fakeMessage1.participantsForReply().to); this.expectContactsEqual(cc, fakeMessage1.participantsForReply().cc); }); - it("should not blow away other participants who have been added to the draft", () => { + it("should not blow away other participants who have been added to the draft", async () => { const randomA = new Contact({email: 'other-guy-a@gmail.com'}); const randomB = new Contact({email: 'other-guy-b@gmail.com'}); this.existingDraft.to = fakeMessage1.participantsForReplyAll().to.concat([randomA]); this.existingDraft.cc = fakeMessage1.participantsForReplyAll().cc.concat([randomB]); - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply', behavior: 'prefer-existing'}) - advanceClock(); - advanceClock(); - const {to, cc} = DatabaseTransaction.prototype.persistModel.mostRecentCall.args[0]; + const {to, cc} = await DraftFactory.createOrUpdateDraftForReply({ + thread: fakeThread, + message: fakeMessage1, + type: 'reply', + behavior: 'prefer-existing', + }) this.expectContactsEqual(to, fakeMessage1.participantsForReply().to.concat([randomA])); this.expectContactsEqual(cc, fakeMessage1.participantsForReply().cc.concat([randomB])); }); @@ -491,15 +496,11 @@ xdescribe('DraftFactory', function draftFactory() { spyOn(DraftFactory, 'createDraftForReply'); }); - it("should call through to createDraftForReply", () => { - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply-all'}) - advanceClock(); - advanceClock(); + it("should call through to createDraftForReply", async () => { + await DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply-all'}) expect(DraftFactory.createDraftForReply).toHaveBeenCalledWith({thread: fakeThread, message: fakeMessage1, type: 'reply-all'}) - DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply'}) - advanceClock(); - advanceClock(); + await DraftFactory.createOrUpdateDraftForReply({thread: fakeThread, message: fakeMessage1, type: 'reply'}) expect(DraftFactory.createDraftForReply).toHaveBeenCalledWith({thread: fakeThread, message: fakeMessage1, type: 'reply'}) }); });