diff options
| author | mo khan <mo@mokhan.ca> | 2017-01-03 11:33:46 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-01-03 11:33:46 -0700 |
| commit | d4e336c8ca295d2f05344dd28470f770c4ff7e44 (patch) | |
| tree | da101562e7f0642284cce8d6123f68bc8da2e303 | |
| parent | 29ee0b60b1fe7cd125dff49a989ba449b69e8ae1 (diff) | |
allow for overriding settings in configuration.
| -rw-r--r-- | app/infrastructure/__tests__/configuration_spec.js | 31 | ||||
| -rw-r--r-- | app/infrastructure/configuration.js | 8 |
2 files changed, 33 insertions, 6 deletions
diff --git a/app/infrastructure/__tests__/configuration_spec.js b/app/infrastructure/__tests__/configuration_spec.js index b534f83..23f4885 100644 --- a/app/infrastructure/__tests__/configuration_spec.js +++ b/app/infrastructure/__tests__/configuration_spec.js @@ -3,11 +3,34 @@ import Configuration from '../configuration'; describe("Configuration", ()=> { let subject = null; - beforeEach(() => { - subject = new Configuration(); + describe("without overrides", () => { + beforeEach(() => { + subject = new Configuration(); + }); + + it ("loads the api host", () => { + expect(subject.value_for("API_HOST")).toEqual('https://www.stronglifters.com') + }); + + it ("loads the default ENV", () => { + expect(subject.value_for("ENV")).toEqual('production') + }); }); - it ("loads the api host", function() { - expect(subject.value_for("API_HOST")).toEqual('https://www.stronglifters.com') + describe("with overrides", () => { + let overrides = null; + + beforeEach(() => { + overrides = { ENV: 'development', API_HOST: 'http://localhost:3000' }; + subject = new Configuration(overrides); + }); + + it ("loads the override for API_HOST", function() { + expect(subject.value_for("API_HOST")).toEqual('http://localhost:3000') + }); + + it ("loads the override for ENV", function() { + expect(subject.value_for("ENV")).toEqual('development') + }); }); }); diff --git a/app/infrastructure/configuration.js b/app/infrastructure/configuration.js index 5405cbf..00e8d96 100644 --- a/app/infrastructure/configuration.js +++ b/app/infrastructure/configuration.js @@ -1,10 +1,14 @@ var _defaults = { - API_HOST: 'http://192.168.128.6:3000', + API_HOST: 'https://www.stronglifters.com', ENV: 'production' }; export default class Configuration { + constructor(overrides = _defaults) { + this.overrides = overrides; + } + value_for(key) { - return process.env[key] || _defaults[key]; + return process.env[key] || this.overrides[key]; } } |
