summaryrefslogtreecommitdiff
path: root/app/infrastructure/__tests__/configuration_spec.js
blob: 3dfb101bcb3d12b196dc18666e9446a48fd6c15e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import Configuration from '../configuration';

describe("Configuration", ()=> {
  let subject = null;

  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')
    });
  });

  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", () => {
      expect(subject.value_for("API_HOST")).toEqual('http://localhost:3000')
    });

    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')
    });
  });
});