2015-05-22 09:08:29 +08:00
|
|
|
_ = require 'underscore'
|
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
|
|
|
KeyManager = require('../../src/key-manager').default
|
|
|
|
NylasAPI = require('../../src/flux/nylas-api').default
|
2016-12-02 05:50:31 +08:00
|
|
|
NylasAPIRequest = require('../../src/flux/nylas-api-request').default
|
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
|
|
|
AccountStore = require('../../src/flux/stores/account-store').default
|
2016-05-05 07:23:19 +08:00
|
|
|
Account = require('../../src/flux/models/account').default
|
2016-10-28 09:48:33 +08:00
|
|
|
Actions = require('../../src/flux/actions').default
|
2015-05-22 09:08:29 +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 "AccountStore", ->
|
2015-05-22 09:08:29 +08:00
|
|
|
beforeEach ->
|
2015-08-06 00:44:34 +08:00
|
|
|
@instance = null
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
@constructor = AccountStore.constructor
|
2016-03-15 06:14:08 +08:00
|
|
|
@keys = {}
|
2016-12-06 09:05:15 +08:00
|
|
|
spyOn(KeyManager, 'getPassword').andCallFake (account) =>
|
2016-03-15 06:14:08 +08:00
|
|
|
@keys[account]
|
2016-12-06 09:05:15 +08:00
|
|
|
spyOn(KeyManager, 'deletePassword').andCallFake (account) =>
|
2016-03-15 06:14:08 +08:00
|
|
|
delete @keys[account]
|
2016-12-06 09:05:15 +08:00
|
|
|
spyOn(KeyManager, 'replacePassword').andCallFake (account, pass) =>
|
2016-03-15 06:14:08 +08:00
|
|
|
@keys[account] = pass
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2016-04-27 06:32:00 +08:00
|
|
|
@spyOnConfig = =>
|
2016-03-15 06:14:08 +08:00
|
|
|
@configVersion = 1
|
|
|
|
@configAccounts =
|
|
|
|
[{
|
|
|
|
"id": "A",
|
|
|
|
"client_id" : 'local-4f9d476a-c173',
|
|
|
|
"server_id" : 'A',
|
|
|
|
"email_address":"bengotow@gmail.com",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
},{
|
|
|
|
"id": "B",
|
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
|
|
|
"server_id" : 'B',
|
|
|
|
"email_address":"ben@nylas.com",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
}]
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2016-03-15 06:14:08 +08:00
|
|
|
spyOn(NylasEnv.config, 'get').andCallFake (key) =>
|
2016-05-14 05:16:54 +08:00
|
|
|
return 'production' if key is 'env'
|
2016-03-15 06:14:08 +08:00
|
|
|
return @configAccounts if key is 'nylas.accounts'
|
|
|
|
return @configVersion if key is 'nylas.accountsVersion'
|
|
|
|
return null
|
2015-09-25 05:51:15 +08:00
|
|
|
|
2016-04-27 06:32:00 +08:00
|
|
|
afterEach ->
|
|
|
|
@instance.stopListeningToAll()
|
|
|
|
|
|
|
|
describe "initialization", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(NylasEnv.config, 'set')
|
|
|
|
@spyOnConfig()
|
|
|
|
|
2016-03-15 06:14:08 +08:00
|
|
|
it "should initialize the accounts and version from config", ->
|
|
|
|
@instance = new @constructor
|
|
|
|
expect(@instance._version).toEqual(@configVersion)
|
|
|
|
expect(@instance.accounts()).toEqual([
|
|
|
|
(new Account).fromJSON(@configAccounts[0]),
|
|
|
|
(new Account).fromJSON(@configAccounts[1])
|
|
|
|
])
|
|
|
|
|
2016-12-06 09:05:15 +08:00
|
|
|
it "should initialize tokens from KeyManager", ->
|
|
|
|
jasmine.unspy(KeyManager, 'getPassword')
|
|
|
|
spyOn(KeyManager, 'getPassword').andCallFake (account) =>
|
2016-12-02 05:50:31 +08:00
|
|
|
return 'AL-TOKEN' if account is 'bengotow@gmail.com.localSync'
|
|
|
|
return 'AC-TOKEN' if account is 'bengotow@gmail.com.n1Cloud'
|
|
|
|
return 'BL-TOKEN' if account is 'ben@nylas.com.localSync'
|
|
|
|
return 'BC-TOKEN' if account is 'ben@nylas.com.n1Cloud'
|
2016-03-15 06:14:08 +08:00
|
|
|
return null
|
|
|
|
@instance = new @constructor
|
2016-12-02 05:50:31 +08:00
|
|
|
expect(@instance.tokensForAccountId('A')).toEqual({localSync: 'AL-TOKEN', n1Cloud: 'AC-TOKEN'})
|
|
|
|
expect(@instance.tokensForAccountId('B')).toEqual({localSync: 'BL-TOKEN', n1Cloud: 'BC-TOKEN'})
|
2015-10-01 01:12:12 +08:00
|
|
|
|
2016-02-07 16:39:11 +08:00
|
|
|
describe "accountForEmail", ->
|
|
|
|
beforeEach ->
|
|
|
|
@instance = new @constructor
|
|
|
|
@ac1 = new Account emailAddress: 'juan@nylas.com', aliases: []
|
|
|
|
@ac2 = new Account emailAddress: 'juan@gmail.com', aliases: ['Juan <juanchis@gmail.com>']
|
|
|
|
@ac3 = new Account emailAddress: 'jackie@columbia.edu', aliases: ['Jackie Luo <jacqueline.luo@columbia.edu>']
|
|
|
|
@instance._accounts = [@ac1, @ac2, @ac3]
|
|
|
|
|
|
|
|
it 'returns correct account when no alises present', ->
|
|
|
|
expect(@instance.accountForEmail('juan@nylas.com')).toEqual @ac1
|
|
|
|
|
|
|
|
it 'returns correct account when alias is used', ->
|
|
|
|
expect(@instance.accountForEmail('juanchis@gmail.com')).toEqual @ac2
|
|
|
|
expect(@instance.accountForEmail('jacqueline.luo@columbia.edu')).toEqual @ac3
|
|
|
|
|
2015-10-01 01:12:12 +08:00
|
|
|
describe "adding account from json", ->
|
|
|
|
beforeEach ->
|
|
|
|
@json =
|
2016-03-15 06:14:08 +08:00
|
|
|
"id": "B",
|
2015-10-01 01:12:12 +08:00
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
2016-03-15 06:14:08 +08:00
|
|
|
"server_id" : 'B',
|
2015-10-01 01:12:12 +08:00
|
|
|
"email_address":"ben@nylas.com",
|
2015-10-06 07:22:22 +08:00
|
|
|
"provider":"gmail",
|
2016-12-02 05:50:31 +08:00
|
|
|
"object":"account",
|
|
|
|
"organization_unit": "label",
|
2015-10-01 01:12:12 +08:00
|
|
|
@instance = new @constructor
|
2016-04-27 06:32:00 +08:00
|
|
|
spyOn(NylasEnv.config, "set")
|
2015-10-01 01:12:12 +08:00
|
|
|
spyOn(@instance, "trigger")
|
2016-12-02 05:50:31 +08:00
|
|
|
@instance.addAccountFromJSON(@json, "LOCAL_TOKEN", "CLOUD_TOKEN")
|
2015-10-01 01:12:12 +08:00
|
|
|
|
2016-12-06 09:05:15 +08:00
|
|
|
it "saves the token to KeyManager and to the loaded tokens cache", ->
|
2016-12-02 05:50:31 +08:00
|
|
|
expect(@instance._tokens["B"]).toEqual({n1Cloud: "CLOUD_TOKEN", localSync: "LOCAL_TOKEN"})
|
2016-12-06 09:05:15 +08:00
|
|
|
expect(KeyManager.replacePassword).toHaveBeenCalledWith("ben@nylas.com.localSync", "LOCAL_TOKEN")
|
|
|
|
expect(KeyManager.replacePassword).toHaveBeenCalledWith("ben@nylas.com.n1Cloud", "CLOUD_TOKEN")
|
2015-10-01 01:12:12 +08:00
|
|
|
|
2016-03-15 06:14:08 +08:00
|
|
|
it "saves the account to the accounts cache and saves", ->
|
2015-10-01 01:12:12 +08:00
|
|
|
account = (new Account).fromJSON(@json)
|
|
|
|
expect(@instance._accounts.length).toBe 1
|
|
|
|
expect(@instance._accounts[0]).toEqual account
|
2016-03-24 09:10:15 +08:00
|
|
|
expect(NylasEnv.config.set.calls.length).toBe 3
|
2016-05-17 05:38:46 +08:00
|
|
|
expect(NylasEnv.config.set.calls[0].args).toEqual(['nylas.accountTokens', null])
|
|
|
|
# Version must be updated last since it will trigger other windows to load nylas.accounts
|
|
|
|
expect(NylasEnv.config.set.calls[2].args).toEqual(['nylas.accountsVersion', 1])
|
2015-10-01 01:12:12 +08:00
|
|
|
|
|
|
|
it "triggers", ->
|
|
|
|
expect(@instance.trigger).toHaveBeenCalled()
|
2016-04-27 06:32:00 +08:00
|
|
|
|
|
|
|
describe "when an account with the same ID is already present", ->
|
|
|
|
it "should update it", ->
|
|
|
|
@json =
|
|
|
|
"id": "B",
|
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
|
|
|
"server_id" : 'B',
|
|
|
|
"email_address":"ben@nylas.com",
|
|
|
|
"provider":"gmail",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
@spyOnConfig()
|
|
|
|
@instance = new @constructor
|
|
|
|
spyOn(@instance, "trigger")
|
|
|
|
expect(@instance._accounts.length).toBe 2
|
2016-12-02 05:50:31 +08:00
|
|
|
@instance.addAccountFromJSON(@json, "B-NEW-LOCAL-TOKEN", "B-NEW-CLOUD-TOKEN")
|
2016-04-27 06:32:00 +08:00
|
|
|
expect(@instance._accounts.length).toBe 2
|
|
|
|
|
|
|
|
describe "when an account with the same email, but different ID, is already present", ->
|
|
|
|
it "should update it", ->
|
|
|
|
@json =
|
|
|
|
"id": "NEVER SEEN BEFORE",
|
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
|
|
|
"server_id" : 'NEVER SEEN BEFORE',
|
|
|
|
"email_address":"ben@nylas.com",
|
|
|
|
"provider":"gmail",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
@spyOnConfig()
|
|
|
|
@instance = new @constructor
|
|
|
|
spyOn(@instance, "trigger")
|
|
|
|
expect(@instance._accounts.length).toBe 2
|
2016-12-02 05:50:31 +08:00
|
|
|
@instance.addAccountFromJSON(@json, "B-NEW-LOCAL-TOKEN", "B-NEW-CLOUD-TOKEN")
|
2016-04-27 06:32:00 +08:00
|
|
|
expect(@instance._accounts.length).toBe 2
|
|
|
|
expect(@instance.accountForId('B')).toBe(undefined)
|
|
|
|
expect(@instance.accountForId('NEVER SEEN BEFORE')).not.toBe(undefined)
|
2016-05-14 05:16:54 +08:00
|
|
|
|
|
|
|
describe "refreshHealthOfAccounts", ->
|
|
|
|
beforeEach ->
|
|
|
|
@spyOnConfig()
|
2016-12-02 05:50:31 +08:00
|
|
|
@calledOptions = calledOptions = []
|
|
|
|
|
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 ->
|
2016-12-02 05:50:31 +08:00
|
|
|
options = this.options
|
|
|
|
calledOptions.push(this.options)
|
2016-05-14 05:16:54 +08:00
|
|
|
if options.accountId is 'return-api-error'
|
|
|
|
Promise.reject(new Error("API ERROR"))
|
|
|
|
else
|
|
|
|
Promise.resolve({
|
|
|
|
sync_state: 'running',
|
|
|
|
id: options.accountId,
|
|
|
|
account_id: options.accountId
|
|
|
|
})
|
|
|
|
@instance = new @constructor
|
|
|
|
spyOn(@instance, '_save')
|
|
|
|
|
|
|
|
it "should GET /account for each of the provided account IDs", ->
|
|
|
|
@instance.refreshHealthOfAccounts(['A', 'B'])
|
2016-11-30 08:32:23 +08:00
|
|
|
expect(NylasAPIRequest.prototype.run.callCount).toBe(2)
|
2016-12-02 05:50:31 +08:00
|
|
|
expect(@calledOptions[0].path).toEqual('/account')
|
|
|
|
expect(@calledOptions[0].accountId).toEqual('A')
|
|
|
|
expect(@calledOptions[1].path).toEqual('/account')
|
|
|
|
expect(@calledOptions[1].accountId).toEqual('B')
|
2016-05-14 05:16:54 +08:00
|
|
|
|
|
|
|
it "should update existing account objects and call save exactly once", ->
|
|
|
|
@instance.accountForId('A').syncState = 'invalid'
|
|
|
|
@instance.refreshHealthOfAccounts(['A', 'B'])
|
|
|
|
advanceClock()
|
|
|
|
expect(@instance.accountForId('A').syncState).toEqual('running')
|
|
|
|
expect(@instance._save.callCount).toBe(1)
|
|
|
|
|
|
|
|
it "should ignore accountIds which do not exist locally when the request completes", ->
|
|
|
|
@instance.accountForId('A').syncState = 'invalid'
|
|
|
|
@instance.refreshHealthOfAccounts(['gone', 'A', 'B'])
|
|
|
|
advanceClock()
|
|
|
|
expect(@instance.accountForId('A').syncState).toEqual('running')
|
|
|
|
expect(@instance._save.callCount).toBe(1)
|
|
|
|
|
|
|
|
it "should not stop if a single GET /account fails", ->
|
|
|
|
@instance.accountForId('B').syncState = 'invalid'
|
|
|
|
@instance.refreshHealthOfAccounts(['return-api-error', 'B']).catch (e) =>
|
|
|
|
advanceClock()
|
|
|
|
expect(@instance.accountForId('B').syncState).toEqual('running')
|
|
|
|
expect(@instance._save.callCount).toBe(1)
|