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
6 changes: 4 additions & 2 deletions modules/ui/src/app/pages/certificates/certificates.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@ export class CertificatesStore extends ComponentStore<AppComponentState> {
exhaustMap((name: string) => {
return this.testRunService.deleteCertificate(name).pipe(
withLatestFrom(this.certificates$),
tap(([, current]) => {
this.removeCertificate(name, current);
tap(([remove, current]) => {
if (remove) {
this.removeCertificate(name, current);
}
})
);
})
Expand Down
6 changes: 4 additions & 2 deletions modules/ui/src/app/pages/reports/reports.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ export class ReportsStore extends ComponentStore<ReportsComponentState> {
exhaustMap(({ mac_addr, started }) => {
return this.testRunService.deleteReport(mac_addr, started || '').pipe(
withLatestFrom(this.history$),
tap(([, current]) => {
this.removeReport(mac_addr, started, current);
tap(([remove, current]) => {
if (remove) {
this.removeReport(mac_addr, started, current);
}
})
);
})
Expand Down
32 changes: 32 additions & 0 deletions modules/ui/src/app/services/test-run.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,24 @@ describe('TestRunService', () => {
req.flush({});
});

it('deleteReport should return false when error happens', () => {
const apiUrl = 'http://localhost:8000/report';

service.deleteReport(device.mac_addr, '').subscribe(res => {
expect(res).toEqual(false);
});

const req = httpTestingController.expectOne(apiUrl);
expect(req.request.method).toBe('DELETE');
expect(req.request.body).toEqual(
JSON.stringify({
mac_addr: device.mac_addr,
timestamp: '',
})
);
req.error(new ErrorEvent(''));
});

it('#saveDevice should have necessary request data', () => {
const apiUrl = 'http://localhost:8000/device';

Expand Down Expand Up @@ -503,4 +521,18 @@ describe('TestRunService', () => {

req.flush(true);
});

it('deleteCertificate should return false when error happens', () => {
service.deleteCertificate('test').subscribe(res => {
expect(res).toEqual(false);
});

const req = httpTestingController.expectOne(
'http://localhost:8000/system/config/certs/delete'
);

expect(req.request.method).toBe('DELETE');

req.error(new ErrorEvent(''));
});
});
10 changes: 8 additions & 2 deletions modules/ui/src/app/services/test-run.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ export class TestRunService {
.delete<boolean>(`${API_URL}/report`, {
body: JSON.stringify({ mac_addr, timestamp: started }),
})
.pipe(map(() => true));
.pipe(
catchError(() => of(false)),
map(res => !!res)
);
}

fetchCertificates(): Observable<Certificate[]> {
Expand All @@ -228,7 +231,10 @@ export class TestRunService {
.delete<boolean>(`${API_URL}/system/config/certs/delete`, {
body: JSON.stringify({ name }),
})
.pipe(map(() => true));
.pipe(
catchError(() => of(false)),
map(res => !!res)
);
}

uploadCertificate(file: File): Observable<boolean> {
Expand Down