mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-21 07:27:51 +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"
|
serverId: "server-123"
|
||||||
draft: true
|
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')
|
task = new SendDraftTask('local-123')
|
||||||
waitsForPromise => task.performLocal().then =>
|
waitsForPromise => task.performLocal().then =>
|
||||||
expect(task.backupDraft).toBeDefined()
|
expect(task.backupDraft).toBeDefined()
|
||||||
expect(task.backupDraft.clientId).toBe "local-123"
|
expect(task.backupDraft.clientId).toBe "local-123"
|
||||||
expect(task.backupDraft.serverId).toBe "server-123"
|
expect(task.backupDraft.serverId).toBe "server-123"
|
||||||
expect(task.backupDraft).not.toBe draft # It's a clone
|
expect(task.backupDraft).not.toBe draft # It's a clone
|
||||||
|
expect(calledBody).toBe Message.attributes.body
|
||||||
|
|
||||||
describe "performRemote", ->
|
describe "performRemote", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -118,8 +125,7 @@ describe "SendDraftTask", ->
|
||||||
it "throws a `NotFoundError` if the model is blank", ->
|
it "throws a `NotFoundError` if the model is blank", ->
|
||||||
spyOn(@task, "_notifyUserOfError")
|
spyOn(@task, "_notifyUserOfError")
|
||||||
spyOn(@task, "_permanentError").andCallThrough()
|
spyOn(@task, "_permanentError").andCallThrough()
|
||||||
jasmine.unspy(DatabaseStore, "findBy")
|
@draftResolver = -> Promise.resolve(null)
|
||||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.resolve(null)
|
|
||||||
waitsForPromise => @task.performRemote().then =>
|
waitsForPromise => @task.performRemote().then =>
|
||||||
expect(DBt.persistModel.callCount).toBe 1
|
expect(DBt.persistModel.callCount).toBe 1
|
||||||
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
||||||
|
@ -128,8 +134,7 @@ describe "SendDraftTask", ->
|
||||||
it "throws a `NotFoundError` if findBy fails", ->
|
it "throws a `NotFoundError` if findBy fails", ->
|
||||||
spyOn(@task, "_notifyUserOfError")
|
spyOn(@task, "_notifyUserOfError")
|
||||||
spyOn(@task, "_permanentError").andCallThrough()
|
spyOn(@task, "_permanentError").andCallThrough()
|
||||||
jasmine.unspy(DatabaseStore, "findBy")
|
@draftResolver = -> Promise.reject(new Error("Test Problem"))
|
||||||
spyOn(DatabaseStore, 'findBy').andReturn Promise.reject(new Error("Problem"))
|
|
||||||
waitsForPromise => @task.performRemote().then =>
|
waitsForPromise => @task.performRemote().then =>
|
||||||
expect(DBt.persistModel.callCount).toBe 1
|
expect(DBt.persistModel.callCount).toBe 1
|
||||||
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
expect(DBt.persistModel).toHaveBeenCalledWith(@backupDraft)
|
||||||
|
@ -321,7 +326,12 @@ describe "SendDraftTask", ->
|
||||||
@task = new SendDraftTask(@draftClientId)
|
@task = new SendDraftTask(@draftClientId)
|
||||||
@backupDraft = @draft.clone()
|
@backupDraft = @draft.clone()
|
||||||
@task.backupDraft = @backupDraft # Since performLocal doesn't run
|
@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 =>
|
it "can complete a full performRemote", -> waitsForPromise =>
|
||||||
@task.performRemote().then (status) ->
|
@task.performRemote().then (status) ->
|
||||||
|
@ -367,7 +377,13 @@ describe "SendDraftTask", ->
|
||||||
@task = new SendDraftTask(@draftClientId)
|
@task = new SendDraftTask(@draftClientId)
|
||||||
@backupDraft = @draft.clone()
|
@backupDraft = @draft.clone()
|
||||||
@task.backupDraft = @backupDraft # Since performLocal doesn't run
|
@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 =>
|
it "can complete a full performRemote", -> waitsForPromise =>
|
||||||
@task.performRemote().then (status) ->
|
@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
|
# 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
|
# draft and notify the user to try again. In order to safely do this
|
||||||
# we need to keep a backup to restore.
|
# 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()
|
@backupDraft = draftModel.clone()
|
||||||
|
|
||||||
performRemote: ->
|
performRemote: ->
|
||||||
|
|
Loading…
Reference in a new issue