mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-03 03:23:45 +08:00
fix(draft): fix draft not sending if it wasn't saved first
This commit is contained in:
parent
344524d259
commit
742d38c4ef
2 changed files with 36 additions and 1 deletions
|
@ -138,3 +138,37 @@ describe "SendDraftTask", ->
|
||||||
expect(atom.inbox.makeRequest.calls.length).toBe(1)
|
expect(atom.inbox.makeRequest.calls.length).toBe(1)
|
||||||
options = atom.inbox.makeRequest.mostRecentCall.args[0]
|
options = atom.inbox.makeRequest.mostRecentCall.args[0]
|
||||||
expect(options.returnsModel).toBe(true)
|
expect(options.returnsModel).toBe(true)
|
||||||
|
|
||||||
|
describe "failing performRemote", ->
|
||||||
|
beforeEach ->
|
||||||
|
@draft = new Message
|
||||||
|
version: '1'
|
||||||
|
id: '1233123AEDF1'
|
||||||
|
namespaceId: 'A12ADE'
|
||||||
|
subject: 'New Draft'
|
||||||
|
draft: true
|
||||||
|
to:
|
||||||
|
name: 'Dummy'
|
||||||
|
email: 'dummy@inboxapp.com'
|
||||||
|
@task = new SendDraftTask(@draft)
|
||||||
|
|
||||||
|
it "throws an error if the draft can't be found", ->
|
||||||
|
spyOn(DatabaseStore, 'findByLocalId').andCallFake (klass, localId) ->
|
||||||
|
Promise.resolve()
|
||||||
|
waitsForPromise =>
|
||||||
|
@task.performRemote().catch (error) ->
|
||||||
|
expect(error.message).toBeDefined()
|
||||||
|
|
||||||
|
it "throws an error if the draft isn't saved", ->
|
||||||
|
spyOn(DatabaseStore, 'findByLocalId').andCallFake (klass, localId) ->
|
||||||
|
Promise.resolve(isSaved: false)
|
||||||
|
waitsForPromise =>
|
||||||
|
@task.performRemote().catch (error) ->
|
||||||
|
expect(error.message).toBeDefined()
|
||||||
|
|
||||||
|
it "throws an error if the DB store has issues", ->
|
||||||
|
spyOn(DatabaseStore, 'findByLocalId').andCallFake (klass, localId) ->
|
||||||
|
Promise.reject("DB error")
|
||||||
|
waitsForPromise =>
|
||||||
|
@task.performRemote().catch (error) ->
|
||||||
|
expect(error).toBe "DB error"
|
||||||
|
|
|
@ -31,7 +31,7 @@ class SendDraftTask extends Task
|
||||||
# recent draft version
|
# recent draft version
|
||||||
DatabaseStore.findByLocalId(Message, @draftLocalId).then (draft) ->
|
DatabaseStore.findByLocalId(Message, @draftLocalId).then (draft) ->
|
||||||
# The draft may have been deleted by another task. Nothing we can do.
|
# The draft may have been deleted by another task. Nothing we can do.
|
||||||
return resolve() unless draft
|
return reject(new Error("We couldn't find the saved draft. Please try again in a couple seconds")) unless draft
|
||||||
return reject(new Error("Cannot send draft that is not saved!")) unless draft.isSaved()
|
return reject(new Error("Cannot send draft that is not saved!")) unless draft.isSaved()
|
||||||
|
|
||||||
atom.inbox.makeRequest
|
atom.inbox.makeRequest
|
||||||
|
@ -46,6 +46,7 @@ class SendDraftTask extends Task
|
||||||
Actions.postNotification({message: "Sent!", type: 'success'})
|
Actions.postNotification({message: "Sent!", type: 'success'})
|
||||||
DatabaseStore.unpersistModel(draft).then(resolve)
|
DatabaseStore.unpersistModel(draft).then(resolve)
|
||||||
error: reject
|
error: reject
|
||||||
|
.catch(reject)
|
||||||
|
|
||||||
onAPIError: ->
|
onAPIError: ->
|
||||||
msg = "Our server is having problems. Your messages has NOT been sent"
|
msg = "Our server is having problems. Your messages has NOT been sent"
|
||||||
|
|
Loading…
Reference in a new issue