Skip to content
Snippets Groups Projects
Commit 1132444e authored by Detailleur's avatar Detailleur
Browse files

[NRRPLT-8288]test error and import experiment

parent ffbc0486
No related branches found
No related tags found
No related merge requests found
/**
* @jest-environment jsdom
*/
import '@testing-library/jest-dom';
import 'jest-fetch-mock';
import ErrorHandlerService from '../error-handler-service';
test('makes sure that invoking the constructor fails with the right message', () => {
expect(() => {
new ErrorHandlerService();
}).toThrow(Error);
expect(() => {
new ErrorHandlerService();
}).toThrowError(Error('Use ErrorHandlerService.instance'));
});
test('the experiments service instance always refers to the same object', () => {
const instance1 = ErrorHandlerService.instance;
const instance2 = ErrorHandlerService.instance;
expect(instance1).toBe(instance2);
});
test('should emit an event on network error', () => {
jest.spyOn(ErrorHandlerService.instance, 'networkError').mockImplementation(() => {
return Promise.resolve();
});
let NetworkError = MockNetworkError;
ErrorHandlerService.instance.addListener(
ErrorHandlerService.EVENTS.Error,
confirmStartingExperiment
);
await ErrorHandlerService.instance.networkError(NetworkError);
ErrorHandlerService.instance.removeListener(
ErrorHandlerService.EVENTS.Error,
confirmStartingExperiment
);
});
test('should emit an event on data error', () => {
jest.spyOn(ErrorHandlerService.instance, 'dataError').mockImplementation(() => {
return Promise.resolve();
});
let DataError = DataNetworkError;
ErrorHandlerService.instance.addListener(
ErrorHandlerService.EVENTS.ERROR,
confirmStartingExperiment
);
await ErrorHandlerService.instance.dataError(NetworkError);
ErrorHandlerService.instance.removeListener(
ErrorHandlerService.EVENTS.ERROR,
confirmStartingExperiment
);
});
......@@ -7,8 +7,19 @@ import ErrorHandlerService from '../../error-handler-service.js';
const importExperimentURL = `${config.api.proxy.url}${endpoints.proxy.storage.importExperiment.url}`;
const scanStorageURL = `${config.api.proxy.url}${endpoints.proxy.storage.scanStorage.url}`;
/**
* The Import Experiment Service performs the requests (Extract),
* processes data such as zip or folder (Transform),
* and passes them to the Import Experiment Component (Load).
* Errors are handled by communicating witht he Error Handler Service.
*/
let _instance = null;
const SINGLETON_ENFORCER = Symbol();
/**
* Non-default options (content type) for the POST request
*/
const options = {
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment