Skip to content

Commit

Permalink
fix(main): bug fix in configuration file in case of prod mode (DEV-491)…
Browse files Browse the repository at this point in the history
… (#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 a6c9e87
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 9 deletions.
108 changes: 103 additions & 5 deletions src/app/app-init.service.spec.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -36,7 +36,6 @@ describe('TestService', () => {
}
}
};

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

const instrumentationConfig: DspInstrumentationConfig = {
Expand All @@ -59,7 +58,7 @@ describe('TestService', () => {
providers: [
{
provide: APP_CONFIG,
useValue: config
useValue: devConfig
},
{
provide: DspInstrumentationToken,
Expand All @@ -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');
Expand Down Expand Up @@ -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');
});
});
10 changes: 6 additions & 4 deletions src/app/app-init.service.ts
Expand Up @@ -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
);
Expand Down

0 comments on commit a6c9e87

Please sign in to comment.