{"size": 1228, "ext": "js", "max_stars_repo_path": "lib/cf/services/src/test/config-test.js", "max_stars_repo_name": "jalberti/cf-abacus", "max_stars_repo_stars_event_min_datetime": "2015-08-08T01:42:35.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-27T23:49:45.000Z", "max_issues_repo_path": "lib/cf/services/src/test/config-test.js", "max_issues_repo_name": "jalberti/cf-abacus", "max_issues_repo_issues_event_min_datetime": "2015-07-27T23:17:17.000Z", "max_issues_repo_issues_event_max_datetime": "2019-10-21T19:37:46.000Z", "max_forks_repo_path": "lib/cf/services/src/test/config-test.js", "max_forks_repo_name": "jalberti/cf-abacus", "max_forks_repo_forks_event_min_datetime": "2015-07-28T23:52:05.000Z", "max_forks_repo_forks_event_max_datetime": "2019-08-22T13:27:32.000Z"}
{"max_stars_count": 98, "max_issues_count": 1166, "max_forks_count": 159, "avg_line_length": 23.6153846154, "max_line_length": 56, "alphanum_fraction": 0.4771986971}
'use strict';

const config = require('../config.js');

describe('config', () => {
  let cfg;

  describe('from environment variables', () => {
    context('environment variables not set', () => {
      before(() => {
        delete process.env.SERVICES;
        cfg = config.loadFromEnvironment();
      });

      it('contains default services', () => {
        expect(cfg.services).to.equal(undefined);
      });
    });

    context('environment variables set', () => {
      before(() => {
        process.env.SERVICES = `{
          "service1":{"plans":["plan1","plan2"]},
          "service2":{"plans":["plan2"]}
        }`;
        cfg = config.loadFromEnvironment();
      });

      it('contains specified services values', () => {
        expect(cfg.services).to.deep.equal({
          service1: {
            plans: ['plan1', 'plan2']
          },
          service2: {
            plans: ['plan2']
          }
        });
      });

      context('when services are invalid json', () => {
        before(() => {
          process.env.SERVICES = 'not-a-json';
        });

        it('should error on loading', () => {
          expect(config.loadFromEnvironment).to.throw();
        });
      });
    });
  });
});
