diff --git a/web/src/app/services/startup-service/startup.service.spec.ts b/web/src/app/services/startup-service/startup.service.spec.ts index edfd827f3..bc6510809 100644 --- a/web/src/app/services/startup-service/startup.service.spec.ts +++ b/web/src/app/services/startup-service/startup.service.spec.ts @@ -40,7 +40,7 @@ describe('StartupService', () => { httpMock = injector.get(HttpTestingController); // UserService provided to the TestBed service = TestBed.get(StartupService); - }) + }); it('should be created', inject([StartupService], () => { expect(service).toBeTruthy(); @@ -53,7 +53,21 @@ describe('StartupService', () => { expect(environment.taskanaRestUrl).toBe(someRestUrl); expect(environment.taskanaLogoutUrl).toBe(someLogoutUrl); 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); expect(req.request.method).toBe('GET'); req.flush(dummyEnvironmentInformation); diff --git a/web/src/app/services/startup-service/startup.service.ts b/web/src/app/services/startup-service/startup.service.ts index c31133d7a..0de139537 100644 --- a/web/src/app/services/startup-service/startup.service.ts +++ b/web/src/app/services/startup-service/startup.service.ts @@ -1,12 +1,12 @@ -import { of } from 'rxjs'; -import { HttpClient } from '@angular/common/http'; -import { Router } from '@angular/router'; -import { environment } from 'app/../environments/environment'; -import { Injectable, Injector } from '@angular/core'; -import { CustomFieldsService } from 'app/services/custom-fields/custom-fields.service'; -import { TaskanaEngineService } from 'app/services/taskana-engine/taskana-engine.service'; -import { map } from 'rxjs/operators'; -import { WindowRefService } from 'app/services/window/window.service'; +import {of} from 'rxjs'; +import {HttpClient} from '@angular/common/http'; +import {Router} from '@angular/router'; +import {environment} from 'app/../environments/environment'; +import {Injectable, Injector} from '@angular/core'; +import {CustomFieldsService} from 'app/services/custom-fields/custom-fields.service'; +import {TaskanaEngineService} from 'app/services/taskana-engine/taskana-engine.service'; +import {map} from 'rxjs/operators'; +import {WindowRefService} from 'app/services/window/window.service'; @Injectable() export class StartupService { @@ -18,37 +18,28 @@ export class StartupService { private window: WindowRefService) { } + public get router(): Router { + return this.injector.get(Router); + } + load(): Promise { 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() { return this.httpClient.get('environments/data-sources/environment-information.json').pipe(map(jsonFile => { - if (jsonFile && environment.taskanaRestUrl === '') { - environment.taskanaRestUrl = jsonFile.taskanaRestUrl === '' ? - window.location.protocol + '//' + window.location.host : jsonFile.taskanaRestUrl; + if (jsonFile && jsonFile.taskanaRestUrl) { + environment.taskanaRestUrl = jsonFile.taskanaRestUrl; } - if (jsonFile && environment.taskanaLogoutUrl === '') { - environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl === '' ? - environment.taskanaRestUrl + '/logout' : jsonFile.taskanaLogoutUrl; - + if (jsonFile && jsonFile.taskanaLogoutUrl) { + environment.taskanaLogoutUrl = jsonFile.taskanaLogoutUrl; } this.customFieldsService.initCustomFields('EN', jsonFile); })).toPromise() - .catch(() => { - return of(true) - }); + .catch(() => { + return of(true) + }); } geCustomizedFieldsFilePromise() { @@ -57,12 +48,19 @@ export class StartupService { this.customFieldsService.initCustomFields('EN', jsonFile); } })).toPromise() - .catch(() => { - return of(true) - }); + .catch(() => { + return of(true) + }); } - public get router(): Router { - return this.injector.get(Router); + private loadEnvironment() { + return this.getEnvironmentFilePromise().then( + () => this.geCustomizedFieldsFilePromise() + ).then( + () => this.taskanaEngineService.getUserInformation() + ).catch(error => { + console.log(error); + //this.window.nativeWindow.location.href = environment.taskanaRestUrl + '/login'; + }); } }