Commit c5f8967
Changed files (3)
app
infrastructure
__tests__
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);
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')
+ });
});
});
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) {