Skip to content

Commit 081e553

Browse files
committed
test: test the internalVersionNumber param
1 parent fc47b51 commit 081e553

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ describe('DatasetsRepository', () => {
222222
false
223223
)
224224
expect(actual.id).toBe(testDatasetIds.numericId)
225+
expect(actual.internalVersionNumber).toBe(1)
225226
})
226227

227228
test('should return dataset when it is deaccessioned and includeDeaccessioned param is set', async () => {
@@ -881,6 +882,7 @@ describe('DatasetsRepository', () => {
881882
false
882883
)
883884

885+
expect(actualUpdatedDataset.internalVersionNumber).toBe(2)
884886
expect(actualUpdatedDataset.metadataBlocks[0].fields.title).toBe(
885887
'Dataset created using the createDataset use case'
886888
)
@@ -919,6 +921,98 @@ describe('DatasetsRepository', () => {
919921
])
920922
})
921923

924+
test('should throw error if trying to update an outdated internal version dataset', async () => {
925+
const testDataset = {
926+
metadataBlockValues: [
927+
{
928+
name: 'citation',
929+
fields: {
930+
title: 'Dataset created using the createDataset use case',
931+
author: [
932+
{
933+
authorName: 'Admin, Dataverse',
934+
authorAffiliation: 'Dataverse.org'
935+
},
936+
{
937+
authorName: 'Owner, Dataverse',
938+
authorAffiliation: 'Dataversedemo.org'
939+
}
940+
],
941+
datasetContact: [
942+
{
943+
datasetContactEmail: '[email protected]',
944+
datasetContactName: 'Finch, Fiona'
945+
}
946+
],
947+
dsDescription: [
948+
{
949+
dsDescriptionValue: 'This is the description of the dataset.'
950+
}
951+
],
952+
subject: ['Medicine, Health and Life Sciences']
953+
}
954+
}
955+
]
956+
}
957+
958+
const metadataBlocksRepository = new MetadataBlocksRepository()
959+
const citationMetadataBlock = await metadataBlocksRepository.getMetadataBlockByName(
960+
'citation'
961+
)
962+
963+
const createdDataset = await sut.createDataset(
964+
testDataset,
965+
[citationMetadataBlock],
966+
ROOT_COLLECTION_ALIAS
967+
)
968+
969+
const actualCreatedDataset = await sut.getDataset(
970+
createdDataset.numericId,
971+
DatasetNotNumberedVersion.LATEST,
972+
false,
973+
false
974+
)
975+
const actualCreatedDatasetInternalVersionNumber = actualCreatedDataset.internalVersionNumber
976+
977+
expect(actualCreatedDataset.internalVersionNumber).toBe(1)
978+
979+
// Now update the dataset and then update again with the same internal version number
980+
const updatedDsDescription = 'This is the updated description of the dataset.'
981+
testDataset.metadataBlockValues[0].fields.dsDescription[0].dsDescriptionValue =
982+
updatedDsDescription
983+
984+
// First update sending the correct internal version number
985+
await sut.updateDataset(
986+
createdDataset.numericId,
987+
testDataset,
988+
[citationMetadataBlock],
989+
actualCreatedDatasetInternalVersionNumber
990+
)
991+
992+
const afterFirstUpdateDataset = await sut.getDataset(
993+
createdDataset.numericId,
994+
DatasetNotNumberedVersion.LATEST,
995+
false,
996+
false
997+
)
998+
999+
expect(afterFirstUpdateDataset.internalVersionNumber).toBe(2)
1000+
1001+
//Now try to update again with the previous internal version number
1002+
const expectedError = new WriteError(
1003+
`[400] Dataset internal version number ${actualCreatedDatasetInternalVersionNumber} is outdated`
1004+
)
1005+
1006+
await expect(
1007+
sut.updateDataset(
1008+
createdDataset.numericId,
1009+
testDataset,
1010+
[citationMetadataBlock],
1011+
actualCreatedDatasetInternalVersionNumber
1012+
)
1013+
).rejects.toThrow(expectedError)
1014+
})
1015+
9221016
test('should return error when dataset does not exist', async () => {
9231017
const expectedError = new WriteError(
9241018
`[404] Dataset with ID ${nonExistentTestDatasetId} not found.`

0 commit comments

Comments
 (0)