[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
This commit is contained in:
Halla Moore 2017-03-21 14:20:11 -07:00
parent 2fe8bee38f
commit b849793a72

View file

@ -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'})
});
});