diff --git a/modules/ui/src/app/services/test-run.service.spec.ts b/modules/ui/src/app/services/test-run.service.spec.ts index 43403f921..f34b1f0e4 100644 --- a/modules/ui/src/app/services/test-run.service.spec.ts +++ b/modules/ui/src/app/services/test-run.service.spec.ts @@ -28,7 +28,7 @@ import { } from '../mocks/progress.mock'; import { StatusOfTestResult, TestrunStatus } from '../model/testrun-status'; import { device } from '../mocks/device.mock'; -import { VERSION } from '../mocks/version.mock'; +import { NEW_VERSION, VERSION } from '../mocks/version.mock'; const MOCK_SYSTEM_CONFIG: SystemConfig = { network: { @@ -380,6 +380,23 @@ describe('TestRunService', () => { }); }); + it('fetchVersion should return old version when error happens', () => { + const version = NEW_VERSION; + const mockErrorResponse = { status: 500, statusText: 'Error' }; + const data = 'Invalid request parameters'; + service.getVersion().next(version); + service.fetchVersion(); + const req = httpTestingController.expectOne( + 'http://localhost:8000/system/version' + ); + expect(req.request.method).toBe('GET'); + req.flush(data, mockErrorResponse); + + service.getVersion().subscribe(res => { + expect(res).toEqual(version); + }); + }); + it('deleteReport should have necessary request data', () => { const apiUrl = 'http://localhost:8000/report'; diff --git a/modules/ui/src/app/services/test-run.service.ts b/modules/ui/src/app/services/test-run.service.ts index b8de6b0b8..7b1ab5619 100644 --- a/modules/ui/src/app/services/test-run.service.ts +++ b/modules/ui/src/app/services/test-run.service.ts @@ -18,7 +18,7 @@ import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/internal/BehaviorSubject'; import { Observable } from 'rxjs/internal/Observable'; import { Device, TestModule } from '../model/device'; -import { map, ReplaySubject, retry } from 'rxjs'; +import { catchError, map, of, ReplaySubject, retry } from 'rxjs'; import { SystemConfig, SystemInterfaces } from '../model/setting'; import { StatusOfTestResult, @@ -72,7 +72,6 @@ export class TestRunService { public systemStatus$ = this.systemStatusSubject.asObservable(); private isTestrunStartedSub$ = new BehaviorSubject(false); public isTestrunStarted$ = this.isTestrunStartedSub$.asObservable(); - // private history = new BehaviorSubject(null); private version = new BehaviorSubject(null); constructor(private http: HttpClient) {} @@ -253,7 +252,11 @@ export class TestRunService { fetchVersion(): void { this.http .get(`${API_URL}/system/version`) - .pipe(retry(1)) + .pipe( + catchError(() => { + return of(this.version.value); + }) + ) .subscribe(version => { this.version.next(version); });