@@ -532,4 +532,82 @@ describe('DatasetsRepository', () => {
532532 ) . rejects . toThrow ( expectedError )
533533 } )
534534 } )
535+
536+ describe ( 'updateDataset' , ( ) => {
537+ test ( 'should update an existing dataset with the provided dataset citation fields' , async ( ) => {
538+ const testDataset = {
539+ metadataBlockValues : [
540+ {
541+ name : 'citation' ,
542+ fields : {
543+ title : 'Dataset created using the createDataset use case' ,
544+ author : [
545+ {
546+ authorName : 'Admin, Dataverse' ,
547+ authorAffiliation : 'Dataverse.org'
548+ } ,
549+ {
550+ authorName : 'Owner, Dataverse' ,
551+ authorAffiliation : 'Dataversedemo.org'
552+ }
553+ ] ,
554+ datasetContact : [
555+ {
556+ datasetContactEmail :
'[email protected] ' , 557+ datasetContactName : 'Finch, Fiona'
558+ }
559+ ] ,
560+ dsDescription : [
561+ {
562+ dsDescriptionValue : 'This is the description of the dataset.'
563+ }
564+ ] ,
565+ subject : [ 'Medicine, Health and Life Sciences' ]
566+ }
567+ }
568+ ]
569+ }
570+
571+ const metadataBlocksRepository = new MetadataBlocksRepository ( )
572+ const citationMetadataBlock = await metadataBlocksRepository . getMetadataBlockByName (
573+ 'citation'
574+ )
575+ const createdDataset = await sut . createDataset (
576+ testDataset ,
577+ [ citationMetadataBlock ] ,
578+ ROOT_COLLECTION_ALIAS
579+ )
580+
581+ const actualCreatedDataset = await sut . getDataset (
582+ createdDataset . numericId ,
583+ DatasetNotNumberedVersion . LATEST ,
584+ false
585+ )
586+
587+ expect (
588+ ( actualCreatedDataset . metadataBlocks [ 0 ] . fields . dsDescription [ 0 ] as DatasetDescription )
589+ . dsDescriptionValue
590+ ) . toBe ( 'This is the description of the dataset.' )
591+
592+ const updatedDsDescription = 'This is the updated description of the dataset.'
593+ testDataset . metadataBlockValues [ 0 ] . fields . dsDescription [ 0 ] . dsDescriptionValue = updatedDsDescription
594+
595+ await sut . updateDataset (
596+ createdDataset . numericId ,
597+ testDataset ,
598+ [ citationMetadataBlock ]
599+ )
600+
601+ const actualUpdatedDataset = await sut . getDataset (
602+ createdDataset . numericId ,
603+ DatasetNotNumberedVersion . LATEST ,
604+ false
605+ )
606+
607+ expect (
608+ ( actualUpdatedDataset . metadataBlocks [ 0 ] . fields . dsDescription [ 0 ] as DatasetDescription )
609+ . dsDescriptionValue
610+ ) . toBe ( updatedDsDescription )
611+ } )
612+ } )
535613} )
0 commit comments