Skip to content

Commit f092e4f

Browse files
authored
Merge pull request #132 from IQSS/fix/create_dataset_use_case
Fix CreateDataset use case
2 parents dc12a7a + 55c703a commit f092e4f

File tree

20 files changed

+328
-39
lines changed

20 files changed

+328
-39
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"ecmaVersion": 2021,
2626
"sourceType": "module",
2727
"project": [
28-
"./tsconfig.json"
28+
"./tsconfig.json",
29+
"./tsconfig.tests.json"
2930
]
3031
},
3132
"rules": {

.github/workflows/deploy_pr.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: deploy_pr
33
on: pull_request
44

55
jobs:
6-
test:
6+
test-unit:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
@@ -17,11 +17,36 @@ jobs:
1717
- name: Run unit tests
1818
run: npm run test:unit
1919

20+
test-integration:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v3
24+
- uses: actions/setup-node@v3
25+
with:
26+
node-version: 19
27+
28+
- name: Install npm dependencies
29+
run: npm ci
30+
2031
- name: Run integration tests
2132
run: npm run test:integration
2233

34+
test-functional:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- uses: actions/setup-node@v3
39+
with:
40+
node-version: 19
41+
42+
- name: Install npm dependencies
43+
run: npm ci
44+
45+
- name: Run functional tests
46+
run: npm run test:functional
47+
2348
publish-gpr:
24-
needs: test
49+
needs: [test-unit, test-integration, test-functional]
2550
runs-on: ubuntu-latest
2651
permissions:
2752
packages: write

jest.config.functional.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import config from './jest.config'
2+
3+
config.modulePathIgnorePatterns = ['<rootDir>/test/unit', '<rootDir>/test/integration']
4+
console.log('RUNNING FUNCTIONAL TESTS')
5+
6+
export default config

jest.config.integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config from './jest.config'
22

3-
config.modulePathIgnorePatterns = ['<rootDir>/test/unit']
3+
config.modulePathIgnorePatterns = ['<rootDir>/test/unit', '<rootDir>/test/functional']
44
console.log('RUNNING INTEGRATION TESTS')
55

66
export default config

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config: Config = {
88
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.ts$',
99
moduleFileExtensions: ['ts', 'js', 'json', 'node'],
1010
coveragePathIgnorePatterns: ['node_modules', 'testHelpers'],
11-
globalSetup: '<rootDir>/test/integration/environment/setup.ts',
11+
globalSetup: '<rootDir>/test/environment/setup.ts',
1212
testTimeout: 25000,
1313
coverageThreshold: {
1414
global: {

jest.config.unit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config from './jest.config'
22

3-
config.modulePathIgnorePatterns = ['<rootDir>/test/integration']
3+
config.modulePathIgnorePatterns = ['<rootDir>/test/integration', '<rootDir>/test/functional']
44
delete config.globalSetup
55
delete config.testTimeout
66
console.log('RUNNING UNIT TESTS')

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"test": "jest -c jest.config.ts",
1313
"test:unit": "jest -c jest.config.unit.ts",
1414
"test:integration": "jest -c jest.config.integration.ts",
15+
"test:functional": "jest -c jest.config.functional.ts",
1516
"test:coverage": "jest --coverage -c jest.config.ts",
1617
"test:coverage:check": "jest --coverage --ci --config jest.config.ts",
1718
"lint": "npm run lint:eslint && npm run lint:prettier",

src/core/infra/repositories/ApiRepository.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ export abstract class ApiRepository {
1313
.get(this.buildRequestUrl(apiEndpoint), this.buildRequestConfig(authRequired, queryParams))
1414
.then((response) => response)
1515
.catch((error) => {
16-
throw new ReadError(
17-
`[${error.response.status}]${
18-
error.response.data ? ` ${error.response.data.message}` : ''
19-
}`
20-
)
16+
throw new ReadError(this.buildErrorMessage(error))
2117
})
2218
}
2319

@@ -34,11 +30,7 @@ export abstract class ApiRepository {
3430
)
3531
.then((response) => response)
3632
.catch((error) => {
37-
throw new WriteError(
38-
`[${error.response.status}]${
39-
error.response.data ? ` ${error.response.data.message}` : ''
40-
}`
41-
)
33+
throw new WriteError(this.buildErrorMessage(error))
4234
})
4335
}
4436

@@ -87,4 +79,12 @@ export abstract class ApiRepository {
8779
private buildRequestUrl(apiEndpoint: string): string {
8880
return `${ApiConfig.dataverseApiUrl}${apiEndpoint}`
8981
}
82+
83+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
84+
private buildErrorMessage(error: any): string {
85+
const status =
86+
error.response && error.response.status ? error.response.status : 'unknown error status'
87+
const message = error.response && error.response.data ? ` ${error.response.data.message}` : ''
88+
return `[${status}]${message}`
89+
}
9090
}

src/datasets/domain/useCases/validators/MultipleMetadataFieldValidator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class MultipleMetadataFieldValidator extends BaseMetadataFieldValidator {
4949
metadataFieldKey: newDatasetMetadataFieldAndValueInfo.metadataFieldKey,
5050
metadataFieldValue: value,
5151
metadataBlockName: newDatasetMetadataFieldAndValueInfo.metadataBlockName,
52-
metadataParentFieldKey: newDatasetMetadataFieldAndValueInfo.metadataFieldKey,
5352
metadataFieldPosition: metadataFieldPosition
5453
})
5554
})

src/datasets/domain/useCases/validators/errors/FieldValidationError.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class FieldValidationError extends ResourceValidationError {
1717
if (parentMetadataFieldName) {
1818
message += ` with parent field ${parentMetadataFieldName}`
1919
}
20-
if (fieldPosition) {
20+
if (fieldPosition != undefined) {
2121
message += ` in position ${fieldPosition}`
2222
}
2323
if (reason) {

0 commit comments

Comments
 (0)