2015-08-27 02:43:10 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
fs = require 'fs'
|
2016-10-28 09:48:33 +08:00
|
|
|
Actions = require('../src/flux/actions').default
|
2016-12-06 03:37:27 +08:00
|
|
|
NylasAPI = require('../src/flux/nylas-api').default
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers = require '../src/flux/nylas-api-helpers'
|
2016-12-02 05:50:31 +08:00
|
|
|
NylasAPIRequest = require('../src/flux/nylas-api-request').default
|
2016-05-04 07:42:28 +08:00
|
|
|
Thread = require('../src/flux/models/thread').default
|
2016-05-05 08:00:53 +08:00
|
|
|
Message = require('../src/flux/models/message').default
|
2016-12-06 03:37:27 +08:00
|
|
|
AccountStore = require('../src/flux/stores/account-store').default
|
2016-10-01 06:24:34 +08:00
|
|
|
DatabaseStore = require('../src/flux/stores/database-store').default
|
2016-09-27 14:44:23 +08:00
|
|
|
DatabaseTransaction = require('../src/flux/stores/database-transaction').default
|
2015-08-27 02:43:10 +08:00
|
|
|
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
xdescribe "NylasAPI", ->
|
2016-03-11 03:06:06 +08:00
|
|
|
|
2015-08-27 02:43:10 +08:00
|
|
|
describe "handleModel404", ->
|
|
|
|
it "should unpersist the model from the cache that was requested", ->
|
|
|
|
model = new Thread(id: 'threadidhere')
|
2015-12-18 03:46:05 +08:00
|
|
|
spyOn(DatabaseTransaction.prototype, 'unpersistModel')
|
2015-08-27 02:43:10 +08:00
|
|
|
spyOn(DatabaseStore, 'find').andCallFake (klass, id) =>
|
2016-11-18 07:37:44 +08:00
|
|
|
return Promise.resolve(model)
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModel404("/threads/#{model.id}")
|
2015-08-27 02:43:10 +08:00
|
|
|
advanceClock()
|
|
|
|
expect(DatabaseStore.find).toHaveBeenCalledWith(Thread, model.id)
|
2015-12-18 03:46:05 +08:00
|
|
|
expect(DatabaseTransaction.prototype.unpersistModel).toHaveBeenCalledWith(model)
|
2015-08-27 02:43:10 +08:00
|
|
|
|
|
|
|
it "should not do anything if the model is not in the cache", ->
|
2015-12-18 03:46:05 +08:00
|
|
|
spyOn(DatabaseTransaction.prototype, 'unpersistModel')
|
2015-08-27 02:43:10 +08:00
|
|
|
spyOn(DatabaseStore, 'find').andCallFake (klass, id) =>
|
2016-11-18 07:37:44 +08:00
|
|
|
return Promise.resolve(null)
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModel404("/threads/1234")
|
2015-08-27 02:43:10 +08:00
|
|
|
advanceClock()
|
|
|
|
expect(DatabaseStore.find).toHaveBeenCalledWith(Thread, '1234')
|
2015-12-18 03:46:05 +08:00
|
|
|
expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalledWith()
|
2015-08-27 02:43:10 +08:00
|
|
|
|
|
|
|
it "should not do anything bad if it doesn't recognize the class", ->
|
|
|
|
spyOn(DatabaseStore, 'find')
|
2015-12-18 03:46:05 +08:00
|
|
|
spyOn(DatabaseTransaction.prototype, 'unpersistModel')
|
2015-08-27 02:43:10 +08:00
|
|
|
waitsForPromise ->
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModel404("/asdasdasd/1234")
|
2015-08-27 02:43:10 +08:00
|
|
|
runs ->
|
|
|
|
expect(DatabaseStore.find).not.toHaveBeenCalled()
|
2015-12-18 03:46:05 +08:00
|
|
|
expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalled()
|
2015-08-27 02:43:10 +08:00
|
|
|
|
|
|
|
it "should not do anything bad if the endpoint only has a single segment", ->
|
|
|
|
spyOn(DatabaseStore, 'find')
|
2015-12-18 03:46:05 +08:00
|
|
|
spyOn(DatabaseTransaction.prototype, 'unpersistModel')
|
2015-08-27 02:43:10 +08:00
|
|
|
waitsForPromise ->
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModel404("/account")
|
2015-08-27 02:43:10 +08:00
|
|
|
runs ->
|
|
|
|
expect(DatabaseStore.find).not.toHaveBeenCalled()
|
2015-12-18 03:46:05 +08:00
|
|
|
expect(DatabaseTransaction.prototype.unpersistModel).not.toHaveBeenCalled()
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2016-02-24 10:35:24 +08:00
|
|
|
describe "handleAuthenticationFailure", ->
|
2016-05-14 05:16:54 +08:00
|
|
|
it "should put the account in an `invalid` state", ->
|
|
|
|
spyOn(Actions, 'updateAccount')
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
spyOn(AccountStore, 'tokensForAccountId').andReturn({localSync: 'token'})
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleAuthenticationFailure('/threads/1234', 'token')
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(Actions.updateAccount).toHaveBeenCalled()
|
|
|
|
expect(Actions.updateAccount.mostRecentCall.args).toEqual([AccountStore.accounts()[0].id, {syncState: 'invalid'}])
|
2016-02-24 10:35:24 +08:00
|
|
|
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
it "should put the N1 Cloud account in an `invalid` state", ->
|
|
|
|
spyOn(Actions, 'updateAccount')
|
|
|
|
spyOn(AccountStore, 'tokensForAccountId').andReturn({n1Cloud: 'token'})
|
|
|
|
NylasAPIHelpers.handleAuthenticationFailure('/threads/1234', 'token', 'N1CloudAPI')
|
|
|
|
expect(Actions.updateAccount).toHaveBeenCalled()
|
|
|
|
expect(Actions.updateAccount.mostRecentCall.args).toEqual([AccountStore.accounts()[0].id, {syncState: 'n1_cloud_auth_failed'}])
|
|
|
|
|
2016-05-14 05:16:54 +08:00
|
|
|
it "should not throw an exception if the account cannot be found", ->
|
|
|
|
spyOn(Actions, 'updateAccount')
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleAuthenticationFailure('/threads/1234', 'token')
|
2016-05-14 05:16:54 +08:00
|
|
|
expect(Actions.updateAccount).not.toHaveBeenCalled()
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2015-09-03 03:22:20 +08:00
|
|
|
describe "handleModelResponse", ->
|
|
|
|
beforeEach ->
|
2015-12-18 03:46:05 +08:00
|
|
|
spyOn(DatabaseTransaction.prototype, "persistModels").andCallFake (models) ->
|
2015-09-03 03:22:20 +08:00
|
|
|
Promise.resolve(models)
|
|
|
|
|
|
|
|
stubDB = ({models, testClass, testMatcher}) ->
|
|
|
|
spyOn(DatabaseStore, "findAll").andCallFake (klass) ->
|
|
|
|
testClass?(klass)
|
|
|
|
where: (matcher) ->
|
|
|
|
testMatcher?(matcher)
|
|
|
|
Promise.resolve(models)
|
2015-08-27 02:43:10 +08:00
|
|
|
|
|
|
|
it "should reject if no JSON is provided", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
waitsForPromise ->
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse()
|
2015-09-03 03:22:20 +08:00
|
|
|
.then -> throw new Error("Should reject!")
|
|
|
|
.catch (err) ->
|
|
|
|
expect(err.message).toEqual "handleModelResponse with no JSON provided"
|
|
|
|
|
2015-08-27 02:43:10 +08:00
|
|
|
it "should resolve if an empty JSON array is provided", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
waitsForPromise ->
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse([])
|
2015-09-03 03:22:20 +08:00
|
|
|
.then (resp) ->
|
|
|
|
expect(resp).toEqual []
|
|
|
|
|
|
|
|
describe "if JSON contains objects which are of unknown types", ->
|
|
|
|
it "should warn and resolve", ->
|
|
|
|
spyOn(console, "warn")
|
|
|
|
waitsForPromise ->
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse([{id: 'a', object: 'unknown'}])
|
2015-09-03 03:22:20 +08:00
|
|
|
.then (resp) ->
|
|
|
|
expect(resp).toEqual []
|
|
|
|
expect(console.warn).toHaveBeenCalled()
|
|
|
|
expect(console.warn.calls.length).toBe 1
|
2015-08-27 02:43:10 +08:00
|
|
|
|
|
|
|
describe "if JSON contains the same object more than once", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
beforeEach ->
|
|
|
|
stubDB(models: [])
|
|
|
|
spyOn(console, "warn")
|
|
|
|
@dupes = [
|
|
|
|
{id: 'a', object: 'thread'}
|
|
|
|
{id: 'a', object: 'thread'}
|
|
|
|
{id: 'b', object: 'thread'}
|
|
|
|
]
|
|
|
|
|
2015-08-27 02:43:10 +08:00
|
|
|
it "should warn", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@dupes)
|
2015-09-03 03:22:20 +08:00
|
|
|
.then ->
|
|
|
|
expect(console.warn).toHaveBeenCalled()
|
|
|
|
expect(console.warn.calls.length).toBe 1
|
|
|
|
|
2015-08-27 02:43:10 +08:00
|
|
|
it "should omit duplicates", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@dupes)
|
2015-09-03 03:22:20 +08:00
|
|
|
.then ->
|
2015-12-18 03:46:05 +08:00
|
|
|
models = DatabaseTransaction.prototype.persistModels.calls[0].args[0]
|
2015-09-03 03:22:20 +08:00
|
|
|
expect(models.length).toBe 2
|
|
|
|
expect(models[0].id).toBe 'a'
|
|
|
|
expect(models[1].id).toBe 'b'
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2016-03-04 04:09:16 +08:00
|
|
|
describe "when items in the JSON are locked and we are not accepting changes to them", ->
|
2015-09-03 03:22:20 +08:00
|
|
|
it "should remove locked models from the set", ->
|
|
|
|
json = [
|
|
|
|
{id: 'a', object: 'thread'}
|
|
|
|
{id: 'b', object: 'thread'}
|
|
|
|
]
|
2016-12-03 07:50:17 +08:00
|
|
|
spyOn(NylasAPI.lockTracker, "acceptRemoteChangesTo").andCallFake (klass, id) ->
|
2015-09-03 03:22:20 +08:00
|
|
|
if id is "a" then return false
|
|
|
|
|
|
|
|
stubDB models: [new Thread(json[1])], testMatcher: (whereMatcher) ->
|
2016-01-26 04:11:57 +08:00
|
|
|
expect(whereMatcher.val).toEqual 'b'
|
2015-09-03 03:22:20 +08:00
|
|
|
|
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(json)
|
2015-09-03 03:22:20 +08:00
|
|
|
.then (models) ->
|
|
|
|
expect(models.length).toBe 1
|
2015-12-18 03:46:05 +08:00
|
|
|
models = DatabaseTransaction.prototype.persistModels.calls[0].args[0]
|
2015-09-03 03:22:20 +08:00
|
|
|
expect(models.length).toBe 1
|
|
|
|
expect(models[0].id).toBe 'b'
|
|
|
|
|
|
|
|
describe "when updating models", ->
|
2016-05-05 08:00:53 +08:00
|
|
|
Message = require('../src/flux/models/message').default
|
2015-09-03 03:22:20 +08:00
|
|
|
beforeEach ->
|
|
|
|
@json = [
|
|
|
|
{id: 'a', object: 'draft', unread: true}
|
|
|
|
{id: 'b', object: 'draft', starred: true}
|
|
|
|
]
|
|
|
|
@existing = new Message(id: 'b', unread: true)
|
|
|
|
stubDB models: [@existing]
|
|
|
|
|
|
|
|
verifyUpdateHappened = (responseModels) ->
|
2015-12-18 03:46:05 +08:00
|
|
|
changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0]
|
2015-09-03 03:22:20 +08:00
|
|
|
expect(changedModels.length).toBe 2
|
|
|
|
expect(changedModels[1].id).toBe 'b'
|
|
|
|
expect(changedModels[1].starred).toBe true
|
|
|
|
# Doesn't override existing values
|
|
|
|
expect(changedModels[1].unread).toBe true
|
|
|
|
expect(responseModels.length).toBe 2
|
|
|
|
expect(responseModels[0].id).toBe 'a'
|
|
|
|
expect(responseModels[0].unread).toBe true
|
|
|
|
|
|
|
|
it "updates found models with new data", ->
|
|
|
|
waitsForPromise =>
|
2016-12-06 03:37:27 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@json).then verifyUpdateHappened
|
2015-09-03 03:22:20 +08:00
|
|
|
|
|
|
|
it "updates if the json version is newer", ->
|
|
|
|
@existing.version = 9
|
|
|
|
@json[1].version = 10
|
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@json).then verifyUpdateHappened
|
2015-09-03 03:22:20 +08:00
|
|
|
|
|
|
|
verifyUpdateStopped = (responseModels) ->
|
2015-12-18 03:46:05 +08:00
|
|
|
changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0]
|
2015-09-03 03:22:20 +08:00
|
|
|
expect(changedModels.length).toBe 1
|
|
|
|
expect(changedModels[0].id).toBe 'a'
|
|
|
|
expect(changedModels[0].unread).toBe true
|
|
|
|
expect(responseModels.length).toBe 2
|
|
|
|
expect(responseModels[1].id).toBe 'b'
|
|
|
|
expect(responseModels[1].starred).toBeUndefined()
|
|
|
|
|
|
|
|
it "doesn't update if the json version is older", ->
|
|
|
|
@existing.version = 10
|
|
|
|
@json[1].version = 9
|
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@json).then verifyUpdateStopped
|
2015-09-03 03:22:20 +08:00
|
|
|
|
|
|
|
it "doesn't update if it's already sent", ->
|
|
|
|
@existing.draft = false
|
|
|
|
@json[1].draft = true
|
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(@json).then verifyUpdateStopped
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2015-09-03 03:22:20 +08:00
|
|
|
describe "handling all types of objects", ->
|
|
|
|
apiObjectToClassMap =
|
2016-10-27 07:01:23 +08:00
|
|
|
"file": require('../src/flux/models/file').default
|
|
|
|
"event": require('../src/flux/models/event').default
|
|
|
|
"label": require('../src/flux/models/label').default
|
|
|
|
"folder": require('../src/flux/models/folder').default
|
2016-05-04 07:42:28 +08:00
|
|
|
"thread": require('../src/flux/models/thread').default
|
2016-05-05 08:00:53 +08:00
|
|
|
"draft": require('../src/flux/models/message').default
|
2016-05-05 07:23:19 +08:00
|
|
|
"account": require('../src/flux/models/account').default
|
2016-05-05 08:00:53 +08:00
|
|
|
"message": require('../src/flux/models/message').default
|
2016-10-27 07:01:23 +08:00
|
|
|
"contact": require('../src/flux/models/contact').default
|
|
|
|
"calendar": require('../src/flux/models/calendar').default
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2015-09-03 03:22:20 +08:00
|
|
|
verifyUpdateHappened = (klass, responseModels) ->
|
2015-12-18 03:46:05 +08:00
|
|
|
changedModels = DatabaseTransaction.prototype.persistModels.calls[0].args[0]
|
2015-09-03 03:22:20 +08:00
|
|
|
expect(changedModels.length).toBe 2
|
|
|
|
expect(changedModels[0].id).toBe 'a'
|
|
|
|
expect(changedModels[1].id).toBe 'b'
|
|
|
|
expect(changedModels[0] instanceof klass).toBe true
|
|
|
|
expect(changedModels[1] instanceof klass).toBe true
|
|
|
|
expect(responseModels.length).toBe 2
|
|
|
|
expect(responseModels[0].id).toBe 'a'
|
|
|
|
expect(responseModels[1].id).toBe 'b'
|
|
|
|
expect(responseModels[0] instanceof klass).toBe true
|
|
|
|
expect(responseModels[1] instanceof klass).toBe true
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2015-09-03 03:22:20 +08:00
|
|
|
_.forEach apiObjectToClassMap, (klass, type) ->
|
|
|
|
it "properly handle the '#{type}' type", ->
|
|
|
|
json = [
|
|
|
|
{id: 'a', object: type}
|
|
|
|
{id: 'b', object: type}
|
|
|
|
]
|
|
|
|
stubDB models: [new klass(id: 'b')]
|
2015-08-27 02:43:10 +08:00
|
|
|
|
2015-09-03 03:22:20 +08:00
|
|
|
verifyUpdate = _.partial(verifyUpdateHappened, klass)
|
|
|
|
waitsForPromise =>
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.handleModelResponse(json).then verifyUpdate
|
2016-03-17 10:27:12 +08:00
|
|
|
|
|
|
|
describe "makeDraftDeletionRequest", ->
|
|
|
|
it "should make an API request to delete the draft", ->
|
|
|
|
draft = new Message(accountId: TEST_ACCOUNT_ID, draft: true, clientId: 'asd', serverId: 'asd')
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
spyOn(NylasAPIRequest.prototype, 'run').andCallFake ->
|
|
|
|
expect(this.options.path).toBe "/drafts/#{draft.serverId}"
|
|
|
|
expect(this.options.accountId).toBe TEST_ACCOUNT_ID
|
|
|
|
expect(this.options.method).toBe "DELETE"
|
|
|
|
expect(this.options.returnsModel).toBe false
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
2016-03-17 10:27:12 +08:00
|
|
|
|
|
|
|
it "should increment the change tracker, preventing any further deltas about the draft", ->
|
|
|
|
draft = new Message(accountId: TEST_ACCOUNT_ID, draft: true, clientId: 'asd', serverId: 'asd')
|
fix(spec): add support for async specs and disable misbehaving ones
More spec fixes
replace process.nextTick with setTimeout(fn, 0) for specs
Also added an unspy in the afterEach
Temporarily disable specs
fix(spec): start fixing specs
Summary:
This is the WIP fix to our spec runner.
Several tests have been completely commented out that will require
substantially more work to fix. These have been added to our sprint
backlog.
Other tests have been fixed to update to new APIs or to deal with genuine
bugs that were introduced without our knowing!
The most common non-trivial change relates to observing the `NylasAPI` and
`NylasAPIRequest`. We used to observe the arguments to `makeRequest`.
Unfortunately `NylasAPIRequest.run` is argumentless. Instead you can do:
`NylasAPIRequest.prototype.run.mostRecentCall.object.options` to get the
`options` passed into the object. the `.object` property grabs the context
of the spy when it was last called.
Fixing these tests uncovered several concerning issues with our test
runner. I spent a while tracking down why our participant-text-field-spec
was failling every so often. I chose that spec because it was the first
spec to likely fail, thereby requiring looking at the least number of
preceding files. I tried binary searching, turning on and off, several
files beforehand only to realize that the failure rate was not determined
by a particular preceding test, but rather the existing and quantity of
preceding tests, AND the number of console.log statements I had. There is
some processor-dependent race condition going on that needs further
investigation.
I also discovered an issue with the file-download-spec. We were getting
errors about it accessing a file, which was very suspicious given the code
stubs out all fs access. This was caused due to a spec that called an
async function outside ot a `waitsForPromise` block or a `waitsFor` block.
The test completed, the spies were cleaned up, but the downstream async
chain was still running. By the time the async chain finished the runner
was already working on the next spec and the spies had been restored
(causing the real fs access to run).
Juan had an idea to kill the specs once one fails to prevent cascading
failures. I'll implement this in the next diff update
Test Plan: npm test
Reviewers: juan, halla, jackie
Differential Revision: https://phab.nylas.com/D3501
Disable other specs
Disable more broken specs
All specs turned off till passing state
Use async-safe versions of spec functions
Add async test spec
Remove unused package code
Remove canary spec
2016-12-13 04:12:20 +08:00
|
|
|
spyOn(NylasAPI, 'incrementRemoteChangeLock')
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
2016-03-17 10:27:12 +08:00
|
|
|
expect(NylasAPI.incrementRemoteChangeLock).toHaveBeenCalledWith(Message, draft.serverId)
|
|
|
|
|
|
|
|
it "should not return a promise or anything else, to avoid accidentally making things dependent on the request", ->
|
|
|
|
draft = new Message(accountId: TEST_ACCOUNT_ID, draft: true, clientId: 'asd', serverId: 'asd')
|
2016-12-03 07:50:17 +08:00
|
|
|
a = NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
2016-03-17 10:27:12 +08:00
|
|
|
expect(a).toBe(undefined)
|
|
|
|
|
|
|
|
it "should not do anything if the draft is missing a serverId", ->
|
|
|
|
draft = new Message(accountId: TEST_ACCOUNT_ID, draft: true, clientId: 'asd', serverId: null)
|
2016-11-30 08:32:23 +08:00
|
|
|
spyOn(NylasAPIRequest.prototype, 'run')
|
2016-12-03 07:50:17 +08:00
|
|
|
NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
2016-11-30 08:32:23 +08:00
|
|
|
expect(NylasAPIRequest.prototype.run).not.toHaveBeenCalled()
|