mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-21 07:46:06 +08:00
fix(specs): Future specs should stub DatabaseStore.run, not find/findBy
This commit is contained in:
parent
d76766fa38
commit
944a5838d8
|
@ -72,12 +72,12 @@ describe "SendDraftTask", ->
|
|||
name: 'Dummy'
|
||||
email: 'dummy@nylas.com'
|
||||
@task = new SendDraftTask(@draftClientId)
|
||||
|
||||
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake (options) =>
|
||||
options.success?(@draft.toJSON())
|
||||
Promise.resolve(@draft.toJSON())
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake (klass, id) =>
|
||||
Promise.resolve(@draft)
|
||||
spyOn(DatabaseStore, 'find').andCallFake (klass, id) =>
|
||||
spyOn(DatabaseStore, 'run').andCallFake (klass, id) =>
|
||||
Promise.resolve(@draft)
|
||||
spyOn(DatabaseStore, 'unpersistModel').andCallFake (draft) ->
|
||||
Promise.resolve()
|
||||
|
@ -85,10 +85,6 @@ describe "SendDraftTask", ->
|
|||
spyOn(Actions, "postNotification")
|
||||
spyOn(Actions, "sendDraftSuccess")
|
||||
|
||||
it "should unpersist when successfully sent", ->
|
||||
waitsForPromise => @task.performRemote().then =>
|
||||
expect(DatabaseStore.unpersistModel).toHaveBeenCalledWith(@draft)
|
||||
|
||||
it "should notify the draft was sent", ->
|
||||
waitsForPromise => @task.performRemote().then =>
|
||||
args = Actions.sendDraftSuccess.calls[0].args[0]
|
||||
|
@ -176,7 +172,7 @@ describe "SendDraftTask", ->
|
|||
|
||||
describe "when the server responds with `Invalid message public ID`", ->
|
||||
it "should resend the draft without the reply_to_message_id key set", ->
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake =>
|
||||
spyOn(DatabaseStore, 'run').andCallFake =>
|
||||
Promise.resolve(@draft)
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake ({body, success, error}) =>
|
||||
if body.reply_to_message_id
|
||||
|
@ -195,7 +191,7 @@ describe "SendDraftTask", ->
|
|||
|
||||
describe "when the server responds with `Invalid thread ID`", ->
|
||||
it "should resend the draft without the thread_id or reply_to_message_id keys set", ->
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake => Promise.resolve(@draft)
|
||||
spyOn(DatabaseStore, 'run').andCallFake => Promise.resolve(@draft)
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake ({body, success, error}) =>
|
||||
new Promise (resolve, reject) =>
|
||||
if body.thread_id
|
||||
|
@ -215,21 +211,21 @@ describe "SendDraftTask", ->
|
|||
console.log(err.trace)
|
||||
|
||||
it "throws an error if the draft can't be found", ->
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake (klass, clientId) ->
|
||||
spyOn(DatabaseStore, 'run').andCallFake (klass, clientId) ->
|
||||
Promise.resolve()
|
||||
waitsForPromise =>
|
||||
@task.performRemote().catch (error) ->
|
||||
expect(error.message).toBeDefined()
|
||||
|
||||
it "throws an error if the draft isn't saved", ->
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake (klass, clientId) ->
|
||||
spyOn(DatabaseStore, 'run').andCallFake (klass, clientId) ->
|
||||
Promise.resolve(serverId: null)
|
||||
waitsForPromise =>
|
||||
@task.performRemote().catch (error) ->
|
||||
expect(error.message).toBeDefined()
|
||||
|
||||
it "throws an error if the DB store has issues", ->
|
||||
spyOn(DatabaseStore, 'findBy').andCallFake (klass, clientId) ->
|
||||
spyOn(DatabaseStore, 'run').andCallFake (klass, clientId) ->
|
||||
Promise.reject("DB error")
|
||||
waitsForPromise =>
|
||||
@task.performRemote().catch (error) ->
|
||||
|
|
|
@ -37,10 +37,11 @@ remoteDraft = -> new Message _.extend {}, testData, {clientId: "local-id", serve
|
|||
|
||||
describe "SyncbackDraftTask", ->
|
||||
beforeEach ->
|
||||
spyOn(DatabaseStore, "findBy").andCallFake (klass, {clientId}) ->
|
||||
if klass is Account
|
||||
spyOn(DatabaseStore, "run").andCallFake (query) ->
|
||||
if query._klass is Account
|
||||
return Promise.resolve(new Account(clientId: 'local-abc123', serverId: 'abc123'))
|
||||
|
||||
clientId = query.matcherValueForModelKey('clientId')
|
||||
if clientId is "localDraftId" then Promise.resolve(localDraft())
|
||||
else if clientId is "remoteDraftId" then Promise.resolve(remoteDraft())
|
||||
else if clientId is "missingDraftId" then Promise.resolve()
|
||||
|
|
|
@ -251,5 +251,12 @@ class ModelQuery
|
|||
sql += sort.orderBySQL(@_klass)
|
||||
sql
|
||||
|
||||
# Introspection
|
||||
# (These are here to make specs easy)
|
||||
|
||||
matcherValueForModelKey: (key) ->
|
||||
matcher = _.find @_matchers, (m) -> m.attr.modelKey = key
|
||||
matcher?.val
|
||||
|
||||
|
||||
module.exports = ModelQuery
|
||||
|
|
Loading…
Reference in a new issue