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