Skip to content

Commit d61739b

Browse files
authored
Merge pull request #166 from IQSS/159-update-current-version
Support publish dataset with update current version
2 parents 3c135eb + ceb8a33 commit d61739b

File tree

6 files changed

+103
-5
lines changed

6 files changed

+103
-5
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ node_modules
44
# intellij
55
.idea
66

7+
# Visual Studio
8+
/.vscode
9+
710
# unit tests
811
coverage
912

docs/useCases.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,15 +506,16 @@ publishDataset.execute(datasetId, versionUpdateType)
506506
_See [use case](../src/datasets/domain/useCases/PublishDataset.ts) implementation_.
507507

508508
The above example publishes the dataset with the specified identifier and performs a minor version update. If the response
509-
is successful, the use case does not return the dataset object, but the HTTP status code `200`. Otherwise, it throws an error.
510-
If you want to perform a major version update, you must set the `versionUpdateType` parameter to `VersionUpdateType.MAJOR`.
511-
509+
is successful, the use case does not return the dataset object, but the HTTP status code `200`. Otherwise, it throws an error.\
510+
If you want to perform a major version update, you must set the `versionUpdateType` parameter to `VersionUpdateType.MAJOR`.\
511+
Superusers can pass `VersionUpdateType.UPDATE_CURRENT` to update metadata without changing the version number. This will overwrite the latest published version and therefore will only work for a dataset that has been published at least once. \*Note that this will only work also if there were no file changes in the update.\
512512
The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
513513

514514
The `versionUpdateType` parameter can be a [VersionUpdateType](../src/datasets/domain/models/VersionUpdateType.ts) enum value, which can be one of the following:
515515

516516
- `VersionUpdateType.MINOR`
517517
- `VersionUpdateType.MAJOR`
518+
- `VersionUpdateType.UPDATE_CURRENT`
518519

519520
## Files
520521

src/datasets/domain/models/Dataset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,6 @@ interface Software extends DatasetMetadataSubField {
186186

187187
export enum VersionUpdateType {
188188
MAJOR = 'major',
189-
MINOR = 'minor'
189+
MINOR = 'minor',
190+
UPDATE_CURRENT = 'updatecurrent'
190191
}

src/datasets/domain/useCases/PublishDataset.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class PublishDataset implements UseCase<void> {
1313
* Publishes a dataset, given its identifier and the type of version update type.
1414
*
1515
* @param {number | string} [datasetId] - The dataset identifier, which can be a string (for persistent identifiers), or a number (for numeric identifiers).
16-
* @param {VersionUpdateType} versionUpdateType - Specifies the type of version update, 'major' or 'minor'.
16+
* @param {VersionUpdateType} versionUpdateType - Specifies the type of version update, 'major', 'minor' or 'updatecurrent'
1717
* @returns {Promise<void>} - This method does not return anything upon successful completion.
1818
*/
1919
async execute(datasetId: number | string, versionUpdateType: VersionUpdateType): Promise<void> {

test/functional/datasets/PublishDataset.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
ApiConfig,
33
createDataset,
44
publishDataset,
5+
updateDataset,
56
VersionUpdateType,
67
WriteError
78
} from '../../../src'
@@ -72,6 +73,28 @@ describe('execute', () => {
7273
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
7374
})
7475

76+
test('should successfully publish a dataset with update current version', async () => {
77+
const createdDatasetIdentifiers = await createDataset.execute(testNewDataset)
78+
79+
const firstPublishResponse = await publishDataset.execute(
80+
createdDatasetIdentifiers.persistentId,
81+
VersionUpdateType.MAJOR
82+
)
83+
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
84+
85+
await updateDataset.execute(createdDatasetIdentifiers.numericId, testNewDataset)
86+
87+
const secondPublishResponse = await publishDataset.execute(
88+
createdDatasetIdentifiers.persistentId,
89+
VersionUpdateType.UPDATE_CURRENT
90+
)
91+
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
92+
93+
expect(firstPublishResponse).toBeUndefined()
94+
expect(secondPublishResponse).toBeUndefined()
95+
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
96+
})
97+
7598
test('should throw an error when trying to publish a dataset that does not exist', async () => {
7699
const nonExistentTestDatasetId = 'non-existent-dataset'
77100
const expectedError = new WriteError(
@@ -82,4 +105,16 @@ describe('execute', () => {
82105
publishDataset.execute(nonExistentTestDatasetId, VersionUpdateType.MAJOR)
83106
).rejects.toThrow(expectedError)
84107
})
108+
109+
test('should throw an error when trying to publish with the current version a dataset that has never been published before', async () => {
110+
const createdDatasetIdentifiers = await createDataset.execute(testNewDataset)
111+
112+
await waitForNoLocks(createdDatasetIdentifiers.numericId, 10)
113+
114+
await expect(
115+
publishDataset.execute(createdDatasetIdentifiers.numericId, VersionUpdateType.UPDATE_CURRENT)
116+
).rejects.toBeInstanceOf(WriteError)
117+
118+
await deletePublishedDatasetViaApi(createdDatasetIdentifiers.persistentId)
119+
})
85120
})

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,64 @@ describe('DatasetsRepository', () => {
516516
})
517517
})
518518

519+
describe('publish dataset with current version', () => {
520+
let testDatasetIds: CreatedDatasetIdentifiers
521+
522+
beforeEach(async () => {
523+
testDatasetIds = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO)
524+
})
525+
526+
afterEach(async () => {
527+
await deletePublishedDatasetViaApi(testDatasetIds.persistentId)
528+
})
529+
530+
test('should update current dataset version keeping same version number', async () => {
531+
const expectedMajorVersion = 1
532+
533+
await waitForNoLocks(testDatasetIds.numericId, 10)
534+
535+
// Dataset is in draft, so we need to publish it first
536+
await sut.publishDataset(testDatasetIds.numericId, VersionUpdateType.MAJOR)
537+
await waitForNoLocks(testDatasetIds.numericId, 10)
538+
539+
const datasetAfterFirstPublish = await sut.getDataset(
540+
testDatasetIds.numericId,
541+
DatasetNotNumberedVersion.LATEST,
542+
false
543+
)
544+
545+
// Update dataset
546+
const metadataBlocksRepository = new MetadataBlocksRepository()
547+
const citationMetadataBlock = await metadataBlocksRepository.getMetadataBlockByName(
548+
'citation'
549+
)
550+
await sut.updateDataset(testDatasetIds.numericId, TestConstants.TEST_NEW_DATASET_DTO, [
551+
citationMetadataBlock
552+
])
553+
554+
// Update current version
555+
await sut.publishDataset(testDatasetIds.numericId, VersionUpdateType.UPDATE_CURRENT)
556+
await waitForNoLocks(testDatasetIds.numericId, 10)
557+
558+
const datasetAfterUpdatingCurrentVersion = await sut.getDataset(
559+
testDatasetIds.numericId,
560+
DatasetNotNumberedVersion.LATEST,
561+
false
562+
)
563+
564+
expect(datasetAfterFirstPublish.versionInfo.majorNumber).toBe(expectedMajorVersion)
565+
expect(datasetAfterUpdatingCurrentVersion.versionInfo.majorNumber).toBe(expectedMajorVersion)
566+
})
567+
568+
test('should return error when trying to publish with the current version a dataset that has never been published before', async () => {
569+
await waitForNoLocks(testDatasetIds.numericId, 10)
570+
571+
await expect(
572+
sut.publishDataset(testDatasetIds.numericId, VersionUpdateType.UPDATE_CURRENT)
573+
).rejects.toBeInstanceOf(WriteError)
574+
})
575+
})
576+
519577
describe('updateDataset', () => {
520578
test('should update an existing dataset with the provided dataset citation fields', async () => {
521579
const testDataset = {

0 commit comments

Comments
 (0)