|
1 | | -import { createDataset, CreatedDatasetIdentifiers } from '../../../src/datasets' |
| 1 | +import { createDataset, DatasetDTO } from '../../../src/datasets' |
2 | 2 | import { ApiConfig } from '../../../src' |
3 | 3 | import { TestConstants } from '../../testHelpers/TestConstants' |
4 | 4 | import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
@@ -48,16 +48,16 @@ describe('execute', () => { |
48 | 48 | ] |
49 | 49 | } |
50 | 50 | expect.assertions(3) |
51 | | - let createdDatasetIdentifiers: CreatedDatasetIdentifiers |
| 51 | + |
52 | 52 | try { |
53 | | - createdDatasetIdentifiers = await createDataset.execute(testNewDataset) |
54 | | - } catch (error) { |
55 | | - throw new Error('Dataset should be created') |
56 | | - } finally { |
| 53 | + const createdDatasetIdentifiers = await createDataset.execute(testNewDataset) |
| 54 | + |
57 | 55 | expect(createdDatasetIdentifiers).not.toBeNull() |
58 | 56 | expect(createdDatasetIdentifiers.numericId).not.toBeNull() |
59 | 57 | expect(createdDatasetIdentifiers.persistentId).not.toBeNull() |
60 | 58 | await deleteUnpublishedDatasetViaApi(createdDatasetIdentifiers.numericId) |
| 59 | + } catch (error) { |
| 60 | + throw new Error('Dataset should be created') |
61 | 61 | } |
62 | 62 | }) |
63 | 63 |
|
@@ -94,25 +94,25 @@ describe('execute', () => { |
94 | 94 | ] |
95 | 95 | } |
96 | 96 | expect.assertions(5) |
97 | | - let fieldValidationError: FieldValidationError |
| 97 | + let fieldValidationError: FieldValidationError | undefined = undefined |
98 | 98 | try { |
99 | 99 | await createDataset.execute(testNewDataset) |
100 | 100 | throw new Error('Use case should throw an error') |
101 | 101 | } catch (error) { |
102 | 102 | fieldValidationError = error |
103 | 103 | } finally { |
104 | 104 | expect(fieldValidationError).toBeInstanceOf(FieldValidationError) |
105 | | - expect(fieldValidationError.citationBlockName).toEqual('citation') |
106 | | - expect(fieldValidationError.metadataFieldName).toEqual('title') |
107 | | - expect(fieldValidationError.parentMetadataFieldName).toEqual(undefined) |
108 | | - expect(fieldValidationError.message).toEqual( |
| 105 | + expect(fieldValidationError?.citationBlockName).toEqual('citation') |
| 106 | + expect(fieldValidationError?.metadataFieldName).toEqual('title') |
| 107 | + expect(fieldValidationError?.parentMetadataFieldName).toEqual(undefined) |
| 108 | + expect(fieldValidationError?.message).toEqual( |
109 | 109 | 'There was an error when validating the field title from metadata block citation. Reason was: The field should not be empty.' |
110 | 110 | ) |
111 | 111 | } |
112 | 112 | }) |
113 | 113 |
|
114 | 114 | test('should throw an error when a second level required field is missing', async () => { |
115 | | - const testNewDataset = { |
| 115 | + const testNewDataset: DatasetDTO = { |
116 | 116 | metadataBlockValues: [ |
117 | 117 | { |
118 | 118 | name: 'citation', |
@@ -144,19 +144,19 @@ describe('execute', () => { |
144 | 144 | ] |
145 | 145 | } |
146 | 146 | expect.assertions(6) |
147 | | - let fieldValidationError: FieldValidationError |
| 147 | + let fieldValidationError: FieldValidationError | undefined = undefined |
148 | 148 | try { |
149 | 149 | await createDataset.execute(testNewDataset) |
150 | 150 | throw new Error('Use case should throw an error') |
151 | 151 | } catch (error) { |
152 | 152 | fieldValidationError = error |
153 | 153 | } finally { |
154 | 154 | expect(fieldValidationError).toBeInstanceOf(FieldValidationError) |
155 | | - expect(fieldValidationError.citationBlockName).toEqual('citation') |
156 | | - expect(fieldValidationError.metadataFieldName).toEqual('authorName') |
157 | | - expect(fieldValidationError.parentMetadataFieldName).toEqual('author') |
158 | | - expect(fieldValidationError.fieldPosition).toEqual(0) |
159 | | - expect(fieldValidationError.message).toEqual( |
| 155 | + expect(fieldValidationError?.citationBlockName).toEqual('citation') |
| 156 | + expect(fieldValidationError?.metadataFieldName).toEqual('authorName') |
| 157 | + expect(fieldValidationError?.parentMetadataFieldName).toEqual('author') |
| 158 | + expect(fieldValidationError?.fieldPosition).toEqual(0) |
| 159 | + expect(fieldValidationError?.message).toEqual( |
160 | 160 | 'There was an error when validating the field authorName from metadata block citation with parent field author in position 0. Reason was: The field should not be empty.' |
161 | 161 | ) |
162 | 162 | } |
@@ -196,19 +196,19 @@ describe('execute', () => { |
196 | 196 | ] |
197 | 197 | } |
198 | 198 | expect.assertions(6) |
199 | | - let fieldValidationError: FieldValidationError |
| 199 | + let fieldValidationError: FieldValidationError | undefined = undefined |
200 | 200 | try { |
201 | 201 | await createDataset.execute(testNewDataset) |
202 | 202 | throw new Error('Use case should throw an error') |
203 | 203 | } catch (error) { |
204 | 204 | fieldValidationError = error |
205 | 205 | } finally { |
206 | 206 | expect(fieldValidationError).toBeInstanceOf(FieldValidationError) |
207 | | - expect(fieldValidationError.citationBlockName).toEqual('citation') |
208 | | - expect(fieldValidationError.metadataFieldName).toEqual('subject') |
209 | | - expect(fieldValidationError.parentMetadataFieldName).toEqual(undefined) |
210 | | - expect(fieldValidationError.fieldPosition).toEqual(1) |
211 | | - expect(fieldValidationError.message).toEqual( |
| 207 | + expect(fieldValidationError?.citationBlockName).toEqual('citation') |
| 208 | + expect(fieldValidationError?.metadataFieldName).toEqual('subject') |
| 209 | + expect(fieldValidationError?.parentMetadataFieldName).toEqual(undefined) |
| 210 | + expect(fieldValidationError?.fieldPosition).toEqual(1) |
| 211 | + expect(fieldValidationError?.message).toEqual( |
212 | 212 | 'There was an error when validating the field subject from metadata block citation in position 1. Reason was: The field does not have a valid controlled vocabulary value.' |
213 | 213 | ) |
214 | 214 | } |
|
0 commit comments