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 ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv.config, "set")
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
it "doesn't set if it alreayd exists", ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv.config, "get").andReturn "staging"
|
2015-06-18 06:58:58 +08:00
|
|
|
store = new storeConstructor()
|
2015-11-12 02:25:11 +08:00
|
|
|
expect(NylasEnv.config.set).not.toHaveBeenCalled()
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
it "initializes with the correct default in dev mode", ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv, "inDevMode").andReturn true
|
|
|
|
spyOn(NylasEnv.config, "get").andReturn undefined
|
2015-06-18 06:58:58 +08:00
|
|
|
store = new storeConstructor()
|
2015-11-12 02:25:11 +08:00
|
|
|
expect(NylasEnv.config.set).toHaveBeenCalledWith("env", "production")
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
it "initializes with the correct default in production", ->
|
2015-11-12 02:25:11 +08:00
|
|
|
spyOn(NylasEnv, "inDevMode").andReturn false
|
|
|
|
spyOn(NylasEnv.config, "get").andReturn undefined
|
2015-06-18 06:58:58 +08:00
|
|
|
store = new storeConstructor()
|
2015-11-12 02:25:11 +08:00
|
|
|
expect(NylasEnv.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")
|
2015-11-12 02:25:11 +08:00
|
|
|
expect(NylasEnv.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()
|