diff options
| author | mo khan <mo@mokhan.ca> | 2017-01-14 09:37:38 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2017-01-14 09:37:38 -0700 |
| commit | c5f8967d886a480ee423c9dd93f239c6779e6ba2 (patch) | |
| tree | ad6c64498cb96e36724aba3c16cfa797f1889bda | |
| parent | 818d0e04ebb7d95301c671bbcf2fa883d07e092f (diff) | |
merge defaults with overrides.
| -rw-r--r-- | app/boot/wire-up-components-into.js | 2 | ||||
| -rw-r--r-- | app/infrastructure/__tests__/configuration_spec.js | 12 | ||||
| -rw-r--r-- | app/infrastructure/configuration.js | 4 |
3 files changed, 13 insertions, 5 deletions
diff --git a/app/boot/wire-up-components-into.js b/app/boot/wire-up-components-into.js index 3037ab9..a13b719 100644 --- a/app/boot/wire-up-components-into.js +++ b/app/boot/wire-up-components-into.js @@ -21,7 +21,7 @@ export default class WireUpComponentsInto { }); }).asSingleton(); this.registry.register('applicationStorage', ApplicationStorage).asSingleton(); - this.registry.register('configuration', Configuration).asSingleton(); + this.registry.register('configuration', (container) => new Configuration({API_HOST: 'http://192.168.128.6:3000'})).asSingleton(); this.registry.register('api', Api).asSingleton(); this.registerSubscribers(commands); diff --git a/app/infrastructure/__tests__/configuration_spec.js b/app/infrastructure/__tests__/configuration_spec.js index 23f4885..3dfb101 100644 --- a/app/infrastructure/__tests__/configuration_spec.js +++ b/app/infrastructure/__tests__/configuration_spec.js @@ -25,12 +25,20 @@ describe("Configuration", ()=> { subject = new Configuration(overrides); }); - it ("loads the override for API_HOST", function() { + it ("loads the override for API_HOST", () => { expect(subject.value_for("API_HOST")).toEqual('http://localhost:3000') }); - it ("loads the override for ENV", function() { + it ("loads the override for ENV", () => { expect(subject.value_for("ENV")).toEqual('development') }); + + it ("merges defaults with the overrides", () => { + overrides = { API_HOST: 'http://localhost:3000' }; + subject = new Configuration(overrides); + + expect(subject.value_for("ENV")).toEqual('production') + expect(subject.value_for("API_HOST")).toEqual('http://localhost:3000') + }); }); }); diff --git a/app/infrastructure/configuration.js b/app/infrastructure/configuration.js index 00e8d96..40488ff 100644 --- a/app/infrastructure/configuration.js +++ b/app/infrastructure/configuration.js @@ -1,11 +1,11 @@ var _defaults = { API_HOST: 'https://www.stronglifters.com', - ENV: 'production' + ENV: 'production', }; export default class Configuration { constructor(overrides = _defaults) { - this.overrides = overrides; + this.overrides = Object.assign({}, _defaults, overrides); } value_for(key) { |
