diff --git a/jest.config.functional.ts b/jest.config.functional.ts new file mode 100644 index 00000000..01a71ab8 --- /dev/null +++ b/jest.config.functional.ts @@ -0,0 +1,6 @@ +import config from './jest.config' + +config.modulePathIgnorePatterns = ['/test/unit', '/test/integration'] +console.log('RUNNING FUNCTIONAL TESTS') + +export default config diff --git a/jest.config.integration.ts b/jest.config.integration.ts index ffa03b3d..63512eca 100644 --- a/jest.config.integration.ts +++ b/jest.config.integration.ts @@ -1,6 +1,6 @@ import config from './jest.config' -config.modulePathIgnorePatterns = ['/test/unit'] +config.modulePathIgnorePatterns = ['/test/unit', '/test/functional'] console.log('RUNNING INTEGRATION TESTS') export default config diff --git a/jest.config.unit.ts b/jest.config.unit.ts index a4b2af75..b4f34350 100644 --- a/jest.config.unit.ts +++ b/jest.config.unit.ts @@ -1,6 +1,6 @@ import config from './jest.config' -config.modulePathIgnorePatterns = ['/test/integration'] +config.modulePathIgnorePatterns = ['/test/integration', '/test/functional'] delete config.globalSetup delete config.testTimeout console.log('RUNNING UNIT TESTS') diff --git a/package.json b/package.json index 4c2835de..7cd2f089 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "test": "jest -c jest.config.ts", "test:unit": "jest -c jest.config.unit.ts", "test:integration": "jest -c jest.config.integration.ts", + "test:functional": "jest -c jest.config.functional.ts", "test:coverage": "jest --coverage -c jest.config.ts", "test:coverage:check": "jest --coverage --ci --config jest.config.ts", "lint": "npm run lint:eslint && npm run lint:prettier", diff --git a/src/core/infra/repositories/ApiRepository.ts b/src/core/infra/repositories/ApiRepository.ts index 6168ce97..9a29464c 100644 --- a/src/core/infra/repositories/ApiRepository.ts +++ b/src/core/infra/repositories/ApiRepository.ts @@ -13,11 +13,7 @@ export abstract class ApiRepository { .get(this.buildRequestUrl(apiEndpoint), this.buildRequestConfig(authRequired, queryParams)) .then((response) => response) .catch((error) => { - throw new ReadError( - `[${error.response.status}]${ - error.response.data ? ` ${error.response.data.message}` : '' - }` - ) + throw new ReadError(this.buildErrorMessage(error)) }) } @@ -34,11 +30,7 @@ export abstract class ApiRepository { ) .then((response) => response) .catch((error) => { - throw new WriteError( - `[${error.response.status}]${ - error.response.data ? ` ${error.response.data.message}` : '' - }` - ) + throw new WriteError(this.buildErrorMessage(error)) }) } @@ -87,4 +79,12 @@ export abstract class ApiRepository { private buildRequestUrl(apiEndpoint: string): string { return `${ApiConfig.dataverseApiUrl}${apiEndpoint}` } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + private buildErrorMessage(error: any): string { + const status = + error.response && error.response.status ? error.response.status : 'unknown error status' + const message = error.response && error.response.data ? ` ${error.response.data.message}` : '' + return `[${status}]${message}` + } } diff --git a/test/functional/datasets/CreateDataset.test.ts b/test/functional/datasets/CreateDataset.test.ts new file mode 100644 index 00000000..adbd7684 --- /dev/null +++ b/test/functional/datasets/CreateDataset.test.ts @@ -0,0 +1,5 @@ +//import { createDataset, CreatedDatasetIdentifiers } from '../../../src/datasets' + +describe('execute', () => { + test('should create new dataset', async () => {}) +}) diff --git a/tsconfig.json b/tsconfig.json index e77ed292..0343b895 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,8 @@ "test", "jest.config.integration.ts", "jest.config.js", - "jest.config.unit.ts" + "jest.config.unit.ts", + "jest.config.functional.ts" ], "exclude": ["node_modules", "dist"] }