Properly sets defaults for environment variables
This commit is contained in:
parent
7f9dce9b00
commit
e3214aa5dd
|
@ -2,4 +2,5 @@ var ENV = {
|
|||
production: 'false',
|
||||
api: 'apiRoot',
|
||||
irbUrl: 'irbUrl',
|
||||
homeRoute: 'home',
|
||||
};
|
||||
|
|
|
@ -2,14 +2,11 @@ import {AppEnvironment} from 'sartography-workflow-lib';
|
|||
|
||||
declare var ENV;
|
||||
|
||||
const envHas = (key, temp): boolean => (ENV && (ENV[key] !== null) && (ENV[key] !== undefined) && (ENV[key] !== temp));
|
||||
export const _has = (env, key, temp): boolean => env && ![null, undefined, temp, ''].includes(env[key]);
|
||||
|
||||
export const environment: AppEnvironment = {
|
||||
homeRoute: envHas('homeRoute', '$HOME_ROUTE') ? ENV.homeRoute : 'home',
|
||||
production: envHas('production', '$PRODUCTION') ? (ENV.production === 'true') : false,
|
||||
api: envHas('api', '$API_URL') ? ENV.api : 'http://localhost:5000/v1.0',
|
||||
irbUrl: envHas('irbUrl', '$IRB_URL') ? ENV.irbUrl : 'http://localhost:5001',
|
||||
homeRoute: _has(ENV, 'homeRoute', '$HOME_ROUTE') ? ENV.homeRoute : 'home',
|
||||
production: _has(ENV, 'production', '$PRODUCTION') ? (ENV.production === 'true') : false,
|
||||
api: _has(ENV, 'api', '$API_URL') ? ENV.api : 'http://localhost:5000/v1.0',
|
||||
irbUrl: _has(ENV, 'irbUrl', '$IRB_URL') ? ENV.irbUrl : 'http://localhost:5001',
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {environment} from './environment.runtime';
|
||||
import {_has, environment} from './environment.runtime';
|
||||
|
||||
declare var ENV;
|
||||
|
||||
describe('Environments', () => {
|
||||
it('should have settings for all the environments', () => {
|
||||
|
@ -7,5 +8,40 @@ describe('Environments', () => {
|
|||
expect(environment.production).toEqual(false);
|
||||
expect(environment.api).toEqual('apiRoot');
|
||||
expect(environment.irbUrl).toEqual('irbUrl');
|
||||
expect(environment.homeRoute).toEqual('home');
|
||||
});
|
||||
|
||||
it('should check if environment variables are defined', () => {
|
||||
const env = {
|
||||
homeRoute: '$HOME_ROUTE',
|
||||
production: '$PRODUCTION',
|
||||
api: '$API_URL',
|
||||
irbUrl: '$IRB_URL',
|
||||
};
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeFalse();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeFalse();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeFalse();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeFalse();
|
||||
|
||||
env.homeRoute = undefined;
|
||||
env.production = undefined;
|
||||
env.api = undefined;
|
||||
env.irbUrl = undefined;
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeFalse();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeFalse();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeFalse();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeFalse();
|
||||
|
||||
env.homeRoute = 'something';
|
||||
env.production = 'something';
|
||||
env.api = 'something';
|
||||
env.irbUrl = 'something';
|
||||
|
||||
expect(_has(env, 'homeRoute', '$HOME_ROUTE')).toBeTrue();
|
||||
expect(_has(env, 'production', '$PRODUCTION')).toBeTrue();
|
||||
expect(_has(env, 'api', '$API_URL')).toBeTrue();
|
||||
expect(_has(env, 'irbUrl', '$IRB_URL')).toBeTrue();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue