TSK-1008: fixed update of environment-information.json on startup

This commit is contained in:
Mustapha Zorgati 2020-01-07 11:13:59 +01:00 committed by Holger Hagen
parent 9bf352d4bb
commit b64e12d78b
2 changed files with 48 additions and 36 deletions

View File

@ -40,7 +40,7 @@ describe('StartupService', () => {
httpMock = injector.get(HttpTestingController); httpMock = injector.get(HttpTestingController);
// UserService provided to the TestBed // UserService provided to the TestBed
service = TestBed.get(StartupService); service = TestBed.get(StartupService);
}) });
it('should be created', inject([StartupService], () => { it('should be created', inject([StartupService], () => {
expect(service).toBeTruthy(); expect(service).toBeTruthy();
@ -53,7 +53,21 @@ describe('StartupService', () => {
expect(environment.taskanaRestUrl).toBe(someRestUrl); expect(environment.taskanaRestUrl).toBe(someRestUrl);
expect(environment.taskanaLogoutUrl).toBe(someLogoutUrl); expect(environment.taskanaLogoutUrl).toBe(someLogoutUrl);
done(); done();
}) });
const req = httpMock.expectOne(environmentFile);
expect(req.request.method).toBe('GET');
req.flush(dummyEnvironmentInformation);
httpMock.verify();
});
it('should initialize rest and logout url from external file and override previous config', (done) => {
environment.taskanaRestUrl = 'oldRestUrl';
environment.taskanaLogoutUrl = 'oldLogoutUrl';
service.getEnvironmentFilePromise().then((res) => {
expect(environment.taskanaRestUrl).toBe(someRestUrl);
expect(environment.taskanaLogoutUrl).toBe(someLogoutUrl);
done();
});
const req = httpMock.expectOne(environmentFile); const req = httpMock.expectOne(environmentFile);
expect(req.request.method).toBe('GET'); expect(req.request.method).toBe('GET');
req.flush(dummyEnvironmentInformation); req.flush(dummyEnvironmentInformation);

View File

@ -1,12 +1,12 @@
import { of } from 'rxjs'; import {of} from 'rxjs';
import { HttpClient } from '@angular/common/http'; import {HttpClient} from '@angular/common/http';
import { Router } from '@angular/router'; import {Router} from '@angular/router';
import { environment } from 'app/../environments/environment'; import {environment} from 'app/../environments/environment';
import { Injectable, Injector } from '@angular/core'; import {Injectable, Injector} from '@angular/core';
import { CustomFieldsService } from 'app/services/custom-fields/custom-fields.service'; import {CustomFieldsService} from 'app/services/custom-fields/custom-fields.service';
import { TaskanaEngineService } from 'app/services/taskana-engine/taskana-engine.service'; import {TaskanaEngineService} from 'app/services/taskana-engine/taskana-engine.service';
import { map } from 'rxjs/operators'; import {map} from 'rxjs/operators';
import { WindowRefService } from 'app/services/window/window.service'; import {WindowRefService} from 'app/services/window/window.service';
@Injectable() @Injectable()
export class StartupService { export class StartupService {
@ -18,37 +18,28 @@ export class StartupService {
private window: WindowRefService) { private window: WindowRefService) {
} }
public get router(): Router {
return this.injector.get(Router);
}
load(): Promise<any> { load(): Promise<any> {
return this.loadEnvironment(); return this.loadEnvironment();
} }
private loadEnvironment() {
return this.getEnvironmentFilePromise().then(
() => this.geCustomizedFieldsFilePromise()
).then(
() => this.taskanaEngineService.getUserInformation()
).catch(error => {
this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login';
});
}
getEnvironmentFilePromise() { getEnvironmentFilePromise() {
return this.httpClient.get<any>('environments/data-sources/environment-information.json').pipe(map(jsonFile => { return this.httpClient.get<any>('environments/data-sources/environment-information.json').pipe(map(jsonFile => {
if (jsonFile && environment.taskanaRestUrl === '') { if (jsonFile && jsonFile.taskanaRestUrl) {
environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ? environment.taskanaRestUrl = jsonFile.taskanaRestUrl;
window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl;
} }
if (jsonFile && environment.taskanaLogoutUrl === '') { if (jsonFile && jsonFile.taskanaLogoutUrl) {
environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl === '' ? environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl;
environment.taskanaRestUrl + '/logout' : jsonFile.taskanaLogoutUrl;
} }
this.customFieldsService.initCustomFields('EN', jsonFile); this.customFieldsService.initCustomFields('EN', jsonFile);
})).toPromise() })).toPromise()
.catch(() => { .catch(() => {
return of(true) return of(true)
}); });
} }
geCustomizedFieldsFilePromise() { geCustomizedFieldsFilePromise() {
@ -57,12 +48,19 @@ export class StartupService {
this.customFieldsService.initCustomFields('EN', jsonFile); this.customFieldsService.initCustomFields('EN', jsonFile);
} }
})).toPromise() })).toPromise()
.catch(() => { .catch(() => {
return of(true) return of(true)
}); });
} }
public get router(): Router { private loadEnvironment() {
return this.injector.get(Router); return this.getEnvironmentFilePromise().then(
() => this.geCustomizedFieldsFilePromise()
).then(
() => this.taskanaEngineService.getUserInformation()
).catch(error => {
console.log(error);
//this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login';
});
} }
} }