Commit 2572430

mo khan <mo@mokhan.ca>
2016-12-24 20:37:05
load configuration for each environment.
1 parent f2bf316
Changed files (3)
app/infrastructure/__tests__/configuration_spec.js
@@ -3,13 +3,27 @@ import Configuration from '../configuration';
 describe("Configuration", ()=> {
   let subject = null;
 
-  beforeEach(()=> {
-    subject = new Configuration('development');
+  describe("development", () => {
+    beforeEach(()=> {
+      subject = new Configuration('development');
+    });
+
+    it ("loads the api host", function() {
+      expect(
+        subject.value_for("API_HOST")
+      ).toEqual('http://localhost:3000')
+    });
   });
 
-  it ("loads the specified configuration", function() {
-    let apiHost='http://192.168.128.6:3000'
+  describe("production", () => {
+    beforeEach(()=> {
+      subject = new Configuration('production');
+    });
 
-    expect(subject.value_for("API_HOST")).toEqual(apiHost)
+    it ("loads the api host", function() {
+      expect(
+        subject.value_for("API_HOST")
+      ).toEqual('https://www.stronglifters.com')
+    });
   });
 });
app/infrastructure/api.js
@@ -46,8 +46,7 @@ export default class Api {
   }
 
   buildUrlFor(url) {
-    //let host = this.configuration.value_for('API_HOST');
-    let host = 'https://localhost:3000';
+    let host = this.configuration.value_for('API_HOST');
     return `${host}/api${url}`
   }
 }
app/infrastructure/configuration.js
@@ -1,11 +1,21 @@
 import Config from 'react-native-config';
 
+var _configuration = {
+  development: {
+    API_HOST: 'http://localhost:3000'
+  },
+  production: {
+    API_HOST: 'https://www.stronglifters.com'
+  }
+};
+
 export default class Configuration {
   constructor(environment) {
     this.environment = environment;
   }
 
   value_for(key) {
-    return Config[key];
+    //return Config[key];
+    return _configuration[this.environment][key];
   }
 }