Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion modules/ui/src/app/services/test-run.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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';

Expand Down
9 changes: 6 additions & 3 deletions modules/ui/src/app/services/test-run.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,7 +72,6 @@ export class TestRunService {
public systemStatus$ = this.systemStatusSubject.asObservable();
private isTestrunStartedSub$ = new BehaviorSubject<boolean>(false);
public isTestrunStarted$ = this.isTestrunStartedSub$.asObservable();
// private history = new BehaviorSubject<TestrunStatus[] | null>(null);
private version = new BehaviorSubject<Version | null>(null);

constructor(private http: HttpClient) {}
Expand Down Expand Up @@ -253,7 +252,11 @@ export class TestRunService {
fetchVersion(): void {
this.http
.get<Version>(`${API_URL}/system/version`)
.pipe(retry(1))
.pipe(
catchError(() => {
return of(this.version.value);
})
)
.subscribe(version => {
this.version.next(version);
});
Expand Down