Commit d4e336c

mo khan <mo@mokhan.ca>
2017-01-03 18:33:46
allow for overriding settings in configuration.
1 parent 29ee0b6
Changed files (2)
app
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')
+    });
   });
 });
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];
   }
 }