|
| 1 | +import { |
| 2 | + createDataset, |
| 3 | + publishDataset, |
| 4 | + VersionUpdateType, |
| 5 | + deleteDataset |
| 6 | +} from '../../../src/datasets' |
| 7 | +import { ApiConfig, WriteError } from '../../../src' |
| 8 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 9 | +import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
| 10 | +import { waitForNoLocks } from '../../testHelpers/datasets/datasetHelper' |
| 11 | + |
| 12 | +const testDataset = { |
| 13 | + license: { |
| 14 | + name: 'CC0 1.0', |
| 15 | + uri: 'http://creativecommons.org/publicdomain/zero/1.0', |
| 16 | + iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png' |
| 17 | + }, |
| 18 | + metadataBlockValues: [ |
| 19 | + { |
| 20 | + name: 'citation', |
| 21 | + fields: { |
| 22 | + title: 'Dataset created using the createDataset use case', |
| 23 | + author: [ |
| 24 | + { |
| 25 | + authorName: 'Admin, Dataverse', |
| 26 | + authorAffiliation: 'Dataverse.org' |
| 27 | + }, |
| 28 | + { |
| 29 | + authorName: 'Owner, Dataverse', |
| 30 | + authorAffiliation: 'Dataversedemo.org' |
| 31 | + } |
| 32 | + ], |
| 33 | + datasetContact: [ |
| 34 | + { |
| 35 | + datasetContactEmail: '[email protected]', |
| 36 | + datasetContactName: 'Finch, Fiona' |
| 37 | + } |
| 38 | + ], |
| 39 | + dsDescription: [ |
| 40 | + { |
| 41 | + dsDescriptionValue: 'This is the description of the dataset.' |
| 42 | + } |
| 43 | + ], |
| 44 | + subject: ['Medicine, Health and Life Sciences'] |
| 45 | + } |
| 46 | + } |
| 47 | + ] |
| 48 | +} |
| 49 | + |
| 50 | +describe('execute', () => { |
| 51 | + beforeEach(async () => { |
| 52 | + ApiConfig.init( |
| 53 | + TestConstants.TEST_API_URL, |
| 54 | + DataverseApiAuthMechanism.API_KEY, |
| 55 | + process.env.TEST_API_KEY |
| 56 | + ) |
| 57 | + }) |
| 58 | + |
| 59 | + test('should delete a dataset when it is published successfully', async () => { |
| 60 | + const createdDatasetIdentifiers = await createDataset.execute(testDataset) |
| 61 | + |
| 62 | + const response = await publishDataset.execute( |
| 63 | + createdDatasetIdentifiers.persistentId, |
| 64 | + VersionUpdateType.MAJOR |
| 65 | + ) |
| 66 | + |
| 67 | + await waitForNoLocks(createdDatasetIdentifiers.numericId, 10) |
| 68 | + |
| 69 | + expect(response).toBeUndefined() |
| 70 | + |
| 71 | + const actual = await deleteDataset.execute(createdDatasetIdentifiers.numericId) |
| 72 | + |
| 73 | + expect(actual).toBeUndefined() |
| 74 | + }) |
| 75 | + |
| 76 | + test('should delete a dataset when it is not published successfully', async () => { |
| 77 | + const createdDatasetIdentifiers = await createDataset.execute(testDataset) |
| 78 | + |
| 79 | + const actual = await deleteDataset.execute(createdDatasetIdentifiers.numericId) |
| 80 | + |
| 81 | + expect(actual).toBeUndefined() |
| 82 | + }) |
| 83 | + |
| 84 | + test('should throw an error when the dataset id is incorrect', async () => { |
| 85 | + await expect(deleteDataset.execute(1111)).rejects.toBeInstanceOf(WriteError) |
| 86 | + }) |
| 87 | +}) |
0 commit comments