Skip to content
Permalink
Browse files
fix(main): bug fix in configuration file in case of prod mode (DEV-491)…
… (#651)

* fix(main): bug fix in app init service

* test(main): test production config

* refactor(main): clean up code
  • Loading branch information
kilchenmann committed Feb 9, 2022
1 parent b0f918c commit a6c9e87d74d47f00450f1cb64d6f533d7191496d
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 9 deletions.
@@ -4,10 +4,10 @@ import { IConfig } from './main/declarations/app-config';
import { APP_CONFIG, DspInstrumentationToken } from './main/declarations/dsp-api-tokens';
import { DspDataDogConfig, DspInstrumentationConfig } from './main/declarations/dsp-instrumentation-config';

describe('TestService', () => {
describe('AppInitService (dev)', () => {
let service: AppInitService;

const config: IConfig = {
const devConfig: IConfig = {
dspRelease: '2022.01.01',
apiProtocol: 'http',
apiHost: '0.0.0.0',
@@ -36,7 +36,6 @@ describe('TestService', () => {
}
}
};

const dspDatadogSpy = new DspDataDogConfig(false, '', '', '', '');

const instrumentationConfig: DspInstrumentationConfig = {
@@ -59,7 +58,7 @@ describe('TestService', () => {
providers: [
{
provide: APP_CONFIG,
useValue: config
useValue: devConfig
},
{
provide: DspInstrumentationToken,
@@ -74,7 +73,7 @@ describe('TestService', () => {
expect(service).toBeTruthy();
});

it('should process the fully specified config', async () => {
it('should process the fully specified config (dev mode)', async () => {
expect(service.dspConfig.release).toEqual('2022.01.01');
expect(service.dspConfig.environment).toEqual('dev');
expect(service.dspConfig.color).toEqual('accent');
@@ -230,3 +229,102 @@ describe('TestService', () => {
});

});


describe('AppInitService (prod)', () => {
let service: AppInitService;

const prodConfig: IConfig = {
dspRelease: '2022.02.01',
apiProtocol: 'https',
apiHost: '0.0.0.0',
apiPort: undefined,
apiPath: '',
iiifProtocol: 'https',
iiifHost: '0.0.0.0',
iiifPort: undefined,
iiifPath: '',
jsonWebToken: 'mytoken',
logErrors: true,
geonameToken: 'geoname_token',
iriBase: 'https://rdfh.ch',
instrumentation: {
environment: 'production',
dataDog: {
enabled: true,
applicationId: 'app_id',
clientToken: 'client_token',
site: 'site',
service: 'dsp-app'
},
rollbar: {
enabled: true,
accessToken: 'rollbar_token'
}
}
};

// const dspDatadogSpy = new DspDataDogConfig(false, '', '', '', '');

const instrumentationConfig: DspInstrumentationConfig = {
environment: 'dev',
dataDog: {
enabled: false,
applicationId: 'app_id',
clientToken: 'client_token',
site: 'site',
service: 'dsp-app'
},
rollbar: {
enabled: false,
accessToken: 'rollbar_token'
}
};

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
{
provide: APP_CONFIG,
useValue: prodConfig
},
{
provide: DspInstrumentationToken,
useValue: instrumentationConfig
},
]
});
service = TestBed.inject(AppInitService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should process the fully specified config (prod mode)', async () => {
expect(service.dspConfig.release).toEqual('2022.02.01');
expect(service.dspConfig.environment).toEqual('production');
expect(service.dspConfig.color).toEqual('primary');
expect(service.dspConfig.production).toEqual(true);
expect(service.dspApiConfig.apiProtocol).toEqual('https');
expect(service.dspApiConfig.apiHost).toEqual('0.0.0.0');
expect(service.dspApiConfig.apiPort).toEqual(null);
expect(service.dspApiConfig.apiPath).toEqual('');
expect(service.dspIiifConfig.iiifProtocol).toEqual('https');
expect(service.dspIiifConfig.iiifHost).toEqual('0.0.0.0');
expect(service.dspIiifConfig.iiifPort).toEqual(null);
expect(service.dspIiifConfig.iiifPath).toEqual('');
expect(service.dspApiConfig.jsonWebToken).toEqual('mytoken');
expect(service.dspApiConfig.logErrors).toEqual(true);
expect(service.dspAppConfig.geonameToken).toEqual('geoname_token');
expect(service.dspAppConfig.iriBase).toEqual('https://rdfh.ch');
expect(service.dspInstrumentationConfig.environment).toEqual('production');
expect(service.dspInstrumentationConfig.dataDog.enabled).toEqual(true);
expect(service.dspInstrumentationConfig.dataDog.applicationId).toEqual('app_id');
expect(service.dspInstrumentationConfig.dataDog.clientToken).toEqual('client_token');
expect(service.dspInstrumentationConfig.dataDog.site).toEqual('site');
expect(service.dspInstrumentationConfig.dataDog.service).toEqual('dsp-app');
expect(service.dspInstrumentationConfig.rollbar.enabled).toEqual(true);
expect(service.dspInstrumentationConfig.rollbar.accessToken).toEqual('rollbar_token');
});
});
@@ -50,20 +50,22 @@ export class AppInitService {
throw new Error('config misses required members: apiProtocol and/or apiHost');
}

const prodMode = (this._config.instrumentation.environment === ('prod' || 'production'));
const env = this._config.instrumentation.environment;

const prodMode = (env.includes('prod') || env.includes('production'));

let color = 'primary';
if (!prodMode) {
if (this._config.instrumentation.environment.includes('staging') || this._config.instrumentation.environment.includes('dev')) {
if (env.includes('staging') || env.includes('dev')) {
color = 'accent';
} else if (this._config.instrumentation.environment.includes('test')){
} else if (env.includes('test')){
color = 'warn';
}
}

this._dspConfig = new DspConfig(
this._config.dspRelease,
this._config.instrumentation.environment,
env,
prodMode,
color
);

0 comments on commit a6c9e87

Please sign in to comment.