2015-05-22 09:08:29 +08:00
|
|
|
_ = require 'underscore'
|
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
|
|
|
AccountStore = require '../../src/flux/stores/account-store'
|
2015-09-25 05:51:15 +08:00
|
|
|
Account = require '../../src/flux/models/account'
|
2016-01-12 06:11:25 +08:00
|
|
|
Actions = require '../../src/flux/actions'
|
2015-05-22 09:08:29 +08:00
|
|
|
|
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
|
|
|
describe "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
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2015-08-06 00:44:34 +08:00
|
|
|
afterEach ->
|
|
|
|
@instance.stopListeningToAll()
|
|
|
|
|
2015-09-25 05:51:15 +08:00
|
|
|
it "should initialize using data saved in config", ->
|
|
|
|
accounts =
|
|
|
|
[{
|
|
|
|
"id": "123",
|
|
|
|
"client_id" : 'local-4f9d476a-c173',
|
|
|
|
"server_id" : '123',
|
|
|
|
"email_address":"bengotow@gmail.com",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
},{
|
|
|
|
"id": "1234",
|
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
|
|
|
"server_id" : '1234',
|
|
|
|
"email_address":"ben@nylas.com",
|
|
|
|
"object":"account"
|
|
|
|
"organization_unit": "label"
|
|
|
|
}]
|
2015-05-22 09:08:29 +08:00
|
|
|
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv.config, 'get').andCallFake (key) ->
|
2016-01-12 06:11:25 +08:00
|
|
|
return accounts if key is 'nylas.accounts'
|
|
|
|
return null
|
2015-08-06 00:44:34 +08:00
|
|
|
@instance = new @constructor
|
2015-09-25 05:51:15 +08:00
|
|
|
|
2016-01-12 06:11:25 +08:00
|
|
|
expect(@instance.accounts()).toEqual([
|
2015-09-25 05:51:15 +08:00
|
|
|
(new Account).fromJSON(accounts[0]),
|
|
|
|
(new Account).fromJSON(accounts[1])
|
|
|
|
])
|
2015-10-01 01:12:12 +08:00
|
|
|
|
|
|
|
describe "adding account from json", ->
|
|
|
|
beforeEach ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv.config, "set")
|
2015-10-01 01:12:12 +08:00
|
|
|
@json =
|
|
|
|
"id": "1234",
|
|
|
|
"client_id" : 'local-4f9d476a-c175',
|
|
|
|
"server_id" : '1234',
|
|
|
|
"email_address":"ben@nylas.com",
|
2015-10-06 07:22:22 +08:00
|
|
|
"provider":"gmail",
|
2015-10-01 01:12:12 +08:00
|
|
|
"object":"account"
|
|
|
|
"auth_token": "auth-123"
|
|
|
|
"organization_unit": "label"
|
|
|
|
@instance = new @constructor
|
2016-01-12 06:11:25 +08:00
|
|
|
spyOn(Actions, 'focusDefaultMailboxPerspectiveForAccount')
|
2015-10-01 01:12:12 +08:00
|
|
|
spyOn(@instance, "trigger")
|
|
|
|
@instance.addAccountFromJSON(@json)
|
|
|
|
|
|
|
|
it "sets the tokens", ->
|
|
|
|
expect(@instance._tokens["1234"]).toBe "auth-123"
|
|
|
|
|
|
|
|
it "sets the accounts", ->
|
|
|
|
account = (new Account).fromJSON(@json)
|
|
|
|
expect(@instance._accounts.length).toBe 1
|
|
|
|
expect(@instance._accounts[0]).toEqual account
|
|
|
|
|
|
|
|
it "saves the config", ->
|
2015-11-12 02:25:11 +08:00
|
|
|
expect(NylasEnv.config.save).toHaveBeenCalled()
|
2016-01-12 06:11:25 +08:00
|
|
|
expect(NylasEnv.config.set.calls.length).toBe 2
|
2015-10-01 01:12:12 +08:00
|
|
|
|
|
|
|
it "selects the account", ->
|
2016-01-12 06:11:25 +08:00
|
|
|
expect(Actions.focusDefaultMailboxPerspectiveForAccount).toHaveBeenCalledWith("1234")
|
2015-10-01 01:12:12 +08:00
|
|
|
|
|
|
|
it "triggers", ->
|
|
|
|
expect(@instance.trigger).toHaveBeenCalled()
|