2015-06-18 06:58:58 +08:00
|
|
|
Actions = require '../lib/onboarding-actions'
|
|
|
|
NylasApiEnvironmentStore = require '../lib/nylas-api-environment-store'
|
|
|
|
storeConstructor = NylasApiEnvironmentStore.constructor
|
|
|
|
|
|
|
|
describe "NylasApiEnvironmentStore", ->
|
|
|
|
beforeEach ->
|
|
|
|
spyOn(atom.config, "set")
|
|
|
|
|
|
|
|
it "doesn't set if it alreayd exists", ->
|
|
|
|
spyOn(atom.config, "get").andReturn "staging"
|
|
|
|
store = new storeConstructor()
|
|
|
|
expect(atom.config.set).not.toHaveBeenCalled()
|
|
|
|
|
|
|
|
it "initializes with the correct default in dev mode", ->
|
|
|
|
spyOn(atom, "inDevMode").andReturn true
|
|
|
|
spyOn(atom.config, "get").andReturn undefined
|
|
|
|
store = new storeConstructor()
|
2015-10-03 06:31:05 +08:00
|
|
|
expect(atom.config.set).toHaveBeenCalledWith("env", "production")
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
it "initializes with the correct default in production", ->
|
|
|
|
spyOn(atom, "inDevMode").andReturn false
|
|
|
|
spyOn(atom.config, "get").andReturn undefined
|
|
|
|
store = new storeConstructor()
|
2015-10-03 06:31:05 +08:00
|
|
|
expect(atom.config.set).toHaveBeenCalledWith("env", "production")
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
describe "when setting the environment", ->
|
|
|
|
it "sets from the desired action", ->
|
2015-10-03 06:31:05 +08:00
|
|
|
Actions.changeAPIEnvironment("staging")
|
|
|
|
expect(atom.config.set).toHaveBeenCalledWith("env", "staging")
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
it "throws if the env is invalid", ->
|
|
|
|
expect( -> Actions.changeAPIEnvironment("bad")).toThrow()
|
|
|
|
|
|
|
|
it "throws if the env is blank", ->
|
|
|
|
expect( -> Actions.changeAPIEnvironment()).toThrow()
|