diff --git a/karma.globals.js b/karma.globals.js index f2903c3..11251d5 100644 --- a/karma.globals.js +++ b/karma.globals.js @@ -2,4 +2,5 @@ var ENV = { production: 'false', api: 'apiRoot', irbUrl: 'irbUrl', + homeRoute: 'home', }; diff --git a/src/environments/environment.runtime.ts b/src/environments/environment.runtime.ts index 9166476..17a3a9f 100644 --- a/src/environments/environment.runtime.ts +++ b/src/environments/environment.runtime.ts @@ -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', }; - - - diff --git a/src/environments/environment.spec.ts b/src/environments/environment.spec.ts index 0741512..5d59b5b 100644 --- a/src/environments/environment.spec.ts +++ b/src/environments/environment.spec.ts @@ -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(); }); });