mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-04 07:10:06 +08:00
fix(spec): fix send-draft spec to test for include
This commit is contained in:
parent
2145627547
commit
3dbdd5cfd6
2 changed files with 24 additions and 8 deletions
|
@ -71,13 +71,20 @@ describe "SendDraftTask", ->
|
|||
serverId: "server-123"
|
||||
draft: true
|
||||
|
||||
spyOn(DatabaseStore, "findBy").andReturn Promise.resolve(draft)
|
||||
calledBody = "ERROR: The body wasn't included!"
|
||||
spyOn(DatabaseStore, "findBy").andCallFake ->
|
||||
then: -> throw new Error("You must include the body!")
|
||||
include: (body) ->
|
||||
calledBody = body
|
||||
return Promise.resolve(draft)
|
||||
|
||||
task = new SendDraftTask('local-123')
|
||||
waitsForPromise => task.performLocal().then =>
|
||||
expect(task.backupDraft).toBeDefined()
|
||||
expect(task.backupDraft.clientId).toBe "local-123"
|
||||
expect(task.backupDraft.serverId).toBe "server-123"
|
||||
expect(task.backupDraft).not.toBe draft # It's a clone
|
||||
expect(calledBody).toBe Message.attributes.body
|
||||
|
||||
describe "performRemote", ->
|
||||
beforeEach ->
|
||||
|
@ -118,8 +125,7 @@ describe "SendDraftTask", ->
|
|||
it "throws a `NotFoundError` if the model is blank", ->
|
||||
spyOn(@task, "_notifyUserOfError")
|
||||
spyOn(@task, "_permanentError").andCallThrough()
|
||||
jasmine.unspy(DatabaseStore, "findBy")
|
||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.resolve(null)
|
||||
@draftResolver = -> Promise.resolve(null)
|
||||
waitsForPromise => @task.performRemote().then =>
|
||||
expect(DBt.persistModel.callCount).toBe 1
|
||||
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
||||
|
@ -128,8 +134,7 @@ describe "SendDraftTask", ->
|
|||
it "throws a `NotFoundError` if findBy fails", ->
|
||||
spyOn(@task, "_notifyUserOfError")
|
||||
spyOn(@task, "_permanentError").andCallThrough()
|
||||
jasmine.unspy(DatabaseStore, "findBy")
|
||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.reject(new Error("Problem"))
|
||||
@draftResolver = -> Promise.reject(new Error("Test Problem"))
|
||||
waitsForPromise => @task.performRemote().then =>
|
||||
expect(DBt.persistModel.callCount).toBe 1
|
||||
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
||||
|
@ -321,7 +326,12 @@ describe "SendDraftTask", ->
|
|||
@task = new SendDraftTask(@draftClientId)
|
||||
@backupDraft = @draft.clone()
|
||||
@task.backupDraft = @backupDraft # Since performLocal doesn't run
|
||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.resolve(@draft)
|
||||
@draftResolver = -> Promise.resolve(@draft)
|
||||
@calledBody = "ERROR: The body wasn't included!"
|
||||
spyOn(DatabaseStore, "findBy").andCallFake =>
|
||||
include: (body) =>
|
||||
@calledBody = body
|
||||
return @draftResolver()
|
||||
|
||||
it "can complete a full performRemote", -> waitsForPromise =>
|
||||
@task.performRemote().then (status) ->
|
||||
|
@ -367,7 +377,13 @@ describe "SendDraftTask", ->
|
|||
@task = new SendDraftTask(@draftClientId)
|
||||
@backupDraft = @draft.clone()
|
||||
@task.backupDraft = @backupDraft # Since performLocal doesn't run
|
||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.resolve(@draft)
|
||||
@draftResolver = -> Promise.resolve(@draft)
|
||||
@calledBody = "ERROR: The body wasn't included!"
|
||||
spyOn(DatabaseStore, "findBy").andCallFake =>
|
||||
then: -> throw new Error("You must include the body!")
|
||||
include: (body) =>
|
||||
@calledBody = body
|
||||
return @draftResolver()
|
||||
|
||||
it "can complete a full performRemote", -> waitsForPromise =>
|
||||
@task.performRemote().then (status) ->
|
||||
|
|
|
@ -45,7 +45,7 @@ class SendDraftTask extends Task
|
|||
# In this scenario, we don't want to send, but want to restore the
|
||||
# draft and notify the user to try again. In order to safely do this
|
||||
# we need to keep a backup to restore.
|
||||
DatabaseStore.findBy(Message, clientId: @draftClientId).then (draftModel) =>
|
||||
DatabaseStore.findBy(Message, clientId: @draftClientId).include(Message.attributes.body).then (draftModel) =>
|
||||
@backupDraft = draftModel.clone()
|
||||
|
||||
performRemote: ->
|
||||
|
|
Loading…
Reference in a new issue