Mailspring/spec-nylas/stores/account-store-spec.coffee
Ben Gotow 297320df94 fix(onboarding): Lots of changes to account management, dead code cleanup
Summary:
Better error handling in the account settings page and a loading spinner

Add Account... replaces "Link External Account", and it works

Clean dead code from onboarding pages, remove base class component

Always show the account switcher

rm dead EdgehillAPI code, AccountStore now manages accounts and credentials in config, not in database

Fix specs

Test Plan: Run tests

Reviewers: dillon, evan

Reviewed By: evan

Projects: #edgehill

Differential Revision: https://phab.nylas.com/D2059
2015-09-24 14:51:15 -07:00

54 lines
1.7 KiB
CoffeeScript

_ = require 'underscore'
AccountStore = require '../../src/flux/stores/account-store'
Account = require '../../src/flux/models/account'
describe "AccountStore", ->
beforeEach ->
@instance = null
@constructor = AccountStore.constructor
afterEach ->
@instance.stopListeningToAll()
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"
}]
spyOn(atom.config, 'get').andCallFake (key) ->
if key is 'nylas.accounts'
return accounts
else if key is 'nylas.currentAccountIndex'
return 1
@instance = new @constructor
expect(@instance.items()).toEqual([
(new Account).fromJSON(accounts[0]),
(new Account).fromJSON(accounts[1])
])
expect(@instance.current() instanceof Account).toBe(true)
expect(@instance.current().id).toEqual(accounts[1]['id'])
expect(@instance.current().emailAddress).toEqual(accounts[1]['email_address'])
it "should initialize current() to null if data is not present", ->
spyOn(atom.config, 'get').andCallFake -> null
@instance = new @constructor
expect(@instance.current()).toEqual(null)
it "should initialize current() to null if data is invalid", ->
spyOn(atom.config, 'get').andCallFake -> "this isn't an object"
@instance = new @constructor
expect(@instance.current()).toEqual(null)