diff --git a/modules/ui/src/app/pages/certificates/certificates.store.ts b/modules/ui/src/app/pages/certificates/certificates.store.ts index 4cc0830ff..ea66433df 100644 --- a/modules/ui/src/app/pages/certificates/certificates.store.ts +++ b/modules/ui/src/app/pages/certificates/certificates.store.ts @@ -96,8 +96,10 @@ export class CertificatesStore extends ComponentStore { 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); + } }) ); }) diff --git a/modules/ui/src/app/pages/reports/reports.store.ts b/modules/ui/src/app/pages/reports/reports.store.ts index 23c63b86e..5725d1a19 100644 --- a/modules/ui/src/app/pages/reports/reports.store.ts +++ b/modules/ui/src/app/pages/reports/reports.store.ts @@ -145,8 +145,10 @@ export class ReportsStore extends ComponentStore { 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); + } }) ); }) 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 1c54810a6..5b7dd703b 100644 --- a/modules/ui/src/app/services/test-run.service.spec.ts +++ b/modules/ui/src/app/services/test-run.service.spec.ts @@ -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'; @@ -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('')); + }); }); diff --git a/modules/ui/src/app/services/test-run.service.ts b/modules/ui/src/app/services/test-run.service.ts index 719f0cfa3..aa3585a9b 100644 --- a/modules/ui/src/app/services/test-run.service.ts +++ b/modules/ui/src/app/services/test-run.service.ts @@ -216,7 +216,10 @@ export class TestRunService { .delete(`${API_URL}/report`, { body: JSON.stringify({ mac_addr, timestamp: started }), }) - .pipe(map(() => true)); + .pipe( + catchError(() => of(false)), + map(res => !!res) + ); } fetchCertificates(): Observable { @@ -228,7 +231,10 @@ export class TestRunService { .delete(`${API_URL}/system/config/certs/delete`, { body: JSON.stringify({ name }), }) - .pipe(map(() => true)); + .pipe( + catchError(() => of(false)), + map(res => !!res) + ); } uploadCertificate(file: File): Observable {