-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPublishDataset.test.ts
More file actions
132 lines (115 loc) · 4.06 KB
/
Copy pathPublishDataset.test.ts
File metadata and controls
132 lines (115 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {
ApiConfig,
createDataset,
publishDataset,
updateDataset,
VersionUpdateType,
WriteError
} from '../../../src'
import { TestConstants } from '../../testHelpers/TestConstants'
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
import {
waitForNoLocks,
deletePublishedDatasetViaApi
} from '../../testHelpers/datasets/datasetHelper'
import { ROOT_COLLECTION_ID } from '../../../src/collections/domain/models/Collection'
// "dataset" is the default so this is equivalent to not passing a datasetType
const datasetType = 'dataset'
const testNewDataset = {
license: {
name: 'CC0 1.0',
uri: 'http://creativecommons.org/publicdomain/zero/1.0',
iconUri: 'https://licensebuttons.net/p/zero/1.0/88x31.png'
},
metadataBlockValues: [
{
name: 'citation',
fields: {
title: 'Dataset created using the createDataset use case',
author: [
{
authorName: 'Admin, Dataverse',
authorAffiliation: 'Dataverse.org'
},
{
authorName: 'Owner, Dataverse',
authorAffiliation: 'Dataversedemo.org'
}
],
datasetContact: [
{
datasetContactEmail: 'finch@mailinator.com',
datasetContactName: 'Finch, Fiona'
}
],
dsDescription: [
{
dsDescriptionValue: 'This is the description of the dataset.'
}
],
subject: ['Medicine, Health and Life Sciences']
}
}
]
}
describe('execute', () => {
beforeEach(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
DataverseApiAuthMechanism.API_KEY,
process.env.TEST_API_KEY
)
})
test('should successfully publish a dataset', async () => {
const createdDatasetIdentifiers = await createDataset.execute(
testNewDataset,
ROOT_COLLECTION_ID,
datasetType
)
const response = await publishDataset.execute(
createdDatasetIdentifiers.persistentId,
VersionUpdateType.MAJOR
)
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
expect(response).toBeUndefined()
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
})
test('should successfully publish a dataset with update current version', async () => {
const createdDatasetIdentifiers = await createDataset.execute(
testNewDataset,
ROOT_COLLECTION_ID,
datasetType
)
const firstPublishResponse = await publishDataset.execute(
createdDatasetIdentifiers.persistentId,
VersionUpdateType.MAJOR
)
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
await updateDataset.execute(createdDatasetIdentifiers.numericId, testNewDataset)
const secondPublishResponse = await publishDataset.execute(
createdDatasetIdentifiers.persistentId,
VersionUpdateType.UPDATE_CURRENT
)
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
expect(firstPublishResponse).toBeUndefined()
expect(secondPublishResponse).toBeUndefined()
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
})
test('should throw an error when trying to publish a dataset that does not exist', async () => {
const nonExistentTestDatasetId = 'non-existent-dataset'
const expectedError = new WriteError(
`[400] Bad dataset ID number: ${nonExistentTestDatasetId}.`
)
await expect(
publishDataset.execute(nonExistentTestDatasetId, VersionUpdateType.MAJOR)
).rejects.toThrow(expectedError)
})
test('should throw an error when trying to publish with the current version a dataset that has never been published before', async () => {
const createdDatasetIdentifiers = await createDataset.execute(testNewDataset)
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
await expect(
publishDataset.execute(createdDatasetIdentifiers.numericId, VersionUpdateType.UPDATE_CURRENT)
).rejects.toBeInstanceOf(WriteError)
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
})
})