Skip to content

Commit 2abed57

Browse files
committed
Added: updateDataset docs and tests
1 parent 550b5fe commit 2abed57

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

docs/localDevelopment.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ These environment variables can be updated as needed for integration testing. Fo
7272
npm run test:coverage
7373
```
7474

75+
### Display container logs while running tests
76+
77+
If you want to see the container logs while running integration or functional tests, run the following command before running the test commands:
78+
79+
```bash
80+
export DEBUG=testcontainers:containers npm test
81+
```
82+
7583
## Format and lint
7684

7785
### Run formatter

docs/useCases.md

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ The different use cases currently available in the package are classified below,
2323
- [List All Datasets](#list-all-datasets)
2424
- [Datasets write use cases](#datasets-write-use-cases)
2525
- [Create a Dataset](#create-a-dataset)
26+
- [Update a Dataset](#update-a-dataset)
2627
- [Publish a Dataset](#publish-a-dataset)
2728
- [Files](#Files)
2829
- [Files read use cases](#files-read-use-cases)
@@ -358,6 +359,66 @@ The above example creates the new dataset in the `root` collection since no coll
358359

359360
The use case returns a [CreatedDatasetIdentifiers](../src/datasets/domain/models/CreatedDatasetIdentifiers.ts) object, which includes the persistent and numeric identifiers of the created dataset.
360361

362+
#### Update a Dataset
363+
364+
Updates an existing Dataset, given a [DatasetDTO](../src/datasets/domain/dtos/DatasetDTO.ts) with the updated information.
365+
366+
If a draft of the dataset already exists, the metadata of that draft is overwritten; otherwise, a new draft is created with the updated metadata.
367+
368+
This use case validates the submitted fields of each metadata block and can return errors of type [ResourceValidationError](../src/core/domain/useCases/validators/errors/ResourceValidationError.ts), which include sufficient information to determine which field value is invalid and why.
369+
370+
##### Example call:
371+
372+
```typescript
373+
import { updateDataset } from '@iqss/dataverse-client-javascript'
374+
375+
/* ... */
376+
377+
const datasetId = 1
378+
const datasetDTO: DatasetDTO = {
379+
metadataBlockValues: [
380+
{
381+
name: 'citation',
382+
fields: {
383+
title: 'Updated Dataset',
384+
author: [
385+
{
386+
authorName: 'John Doe',
387+
authorAffiliation: 'Dataverse'
388+
},
389+
{
390+
authorName: 'John Lee',
391+
authorAffiliation: 'Dataverse'
392+
}
393+
],
394+
datasetContact: [
395+
{
396+
datasetContactEmail: '[email protected]',
397+
datasetContactName: 'John'
398+
}
399+
],
400+
dsDescription: [
401+
{
402+
dsDescriptionValue: 'This is the description of our new dataset'
403+
}
404+
],
405+
subject: 'Earth and Environmental Sciences'
406+
407+
/* Rest of field values... */
408+
}
409+
}
410+
]
411+
}
412+
413+
updateDataset.execute(datasetId, datasetDTO)
414+
415+
/* ... */
416+
```
417+
418+
_See [use case](../src/datasets/domain/useCases/CreateDataset.ts) implementation_.
419+
420+
The `datasetId` parameter can be a string, for persistent identifiers, or a number, for numeric identifiers.
421+
361422
#### Publish a Dataset
362423

363424
Publishes a Dataset, given its identifier and the type of version update to perform.
@@ -372,9 +433,7 @@ import { publishDataset } from '@iqss/dataverse-client-javascript'
372433
const datasetId = 'doi:10.77777/FK2/AAAAAA'
373434
const versionUpdateType = VersionUpdateType.MINOR
374435

375-
publishDataset.execute(datasetId, versionUpdateType).then((publishedDataset: Dataset) => {
376-
/* ... */
377-
})
436+
publishDataset.execute(datasetId, versionUpdateType)
378437

379438
/* ... */
380439
```

test/functional/datasets/UpdateDataset.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('execute', () => {
1818
)
1919
})
2020

21-
test('should update create a dataset when required fields are sent', async () => {
21+
test('should update a dataset when required fields are sent', async () => {
2222
const testDataset = {
2323
metadataBlockValues: [
2424
{

test/integration/datasets/DatasetsRepository.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ describe('DatasetsRepository', () => {
600600
DatasetNotNumberedVersion.LATEST,
601601
false
602602
)
603-
603+
604604
expect(actualUpdatedDataset.metadataBlocks[0].fields.title).toBe(
605605
'Dataset created using the createDataset use case'
606606
)
@@ -632,5 +632,15 @@ describe('DatasetsRepository', () => {
632632
.dsDescriptionValue
633633
).toBe(updatedDsDescription)
634634
})
635+
636+
test('should return error when dataset does not exist', async () => {
637+
const expectedError = new WriteError(
638+
`[404] Dataset with ID ${nonExistentTestDatasetId} not found.`
639+
)
640+
641+
await expect(
642+
sut.publishDataset(nonExistentTestDatasetId, VersionUpdateType.MAJOR)
643+
).rejects.toThrow(expectedError)
644+
})
635645
})
636646
})

0 commit comments

Comments
 (0)