|
| 1 | +import { |
| 2 | + createDataset, |
| 3 | + CreatedDatasetIdentifiers, |
| 4 | + updateDataset, |
| 5 | + getDataset |
| 6 | +} from '../../../src/datasets' |
| 7 | +import { ApiConfig } from '../../../src' |
| 8 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 9 | +import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
| 10 | +import { DatasetDescription } from '../../../src/datasets/domain/models/Dataset' |
| 11 | + |
| 12 | +describe('execute', () => { |
| 13 | + beforeEach(async () => { |
| 14 | + ApiConfig.init( |
| 15 | + TestConstants.TEST_API_URL, |
| 16 | + DataverseApiAuthMechanism.API_KEY, |
| 17 | + process.env.TEST_API_KEY |
| 18 | + ) |
| 19 | + }) |
| 20 | + |
| 21 | + test('should update create a dataset when required fields are sent', async () => { |
| 22 | + const testDataset = { |
| 23 | + metadataBlockValues: [ |
| 24 | + { |
| 25 | + name: 'citation', |
| 26 | + fields: { |
| 27 | + title: 'Dataset created using the createDataset use case', |
| 28 | + author: [ |
| 29 | + { |
| 30 | + authorName: 'Admin, Dataverse', |
| 31 | + authorAffiliation: 'Dataverse.org' |
| 32 | + }, |
| 33 | + { |
| 34 | + authorName: 'Owner, Dataverse', |
| 35 | + authorAffiliation: 'Dataversedemo.org' |
| 36 | + } |
| 37 | + ], |
| 38 | + datasetContact: [ |
| 39 | + { |
| 40 | + datasetContactEmail: '[email protected]', |
| 41 | + datasetContactName: 'Finch, Fiona' |
| 42 | + } |
| 43 | + ], |
| 44 | + dsDescription: [ |
| 45 | + { |
| 46 | + dsDescriptionValue: 'This is the description of the dataset.' |
| 47 | + } |
| 48 | + ], |
| 49 | + subject: ['Medicine, Health and Life Sciences'] |
| 50 | + } |
| 51 | + } |
| 52 | + ] |
| 53 | + } |
| 54 | + |
| 55 | + let createdDatasetIdentifiers: CreatedDatasetIdentifiers |
| 56 | + try { |
| 57 | + createdDatasetIdentifiers = await createDataset.execute(testDataset) |
| 58 | + } catch (error) { |
| 59 | + throw new Error('Dataset should be created') |
| 60 | + } |
| 61 | + |
| 62 | + const datasetId = createdDatasetIdentifiers.numericId |
| 63 | + const updatedDsDescription = 'This is the updated description of the dataset.' |
| 64 | + testDataset.metadataBlockValues[0].fields.dsDescription[0].dsDescriptionValue = |
| 65 | + updatedDsDescription |
| 66 | + await updateDataset.execute(datasetId, testDataset) |
| 67 | + |
| 68 | + const updatedDataset = await getDataset.execute(datasetId) |
| 69 | + expect( |
| 70 | + (updatedDataset.metadataBlocks[0].fields.dsDescription[0] as DatasetDescription) |
| 71 | + .dsDescriptionValue |
| 72 | + ).toEqual(updatedDsDescription) |
| 73 | + }) |
| 74 | +}) |
0 commit comments