@@ -16,7 +16,9 @@ import {
1616 getDatasetFiles ,
1717 restrictFile ,
1818 deleteFile ,
19- linkDataset
19+ linkDataset ,
20+ createDatasetTemplate ,
21+ MetadataFieldTypeClass
2022} from '../../../src'
2123import { ApiConfig } from '../../../src'
2224import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
@@ -58,6 +60,9 @@ import {
5860 DvObjectFeaturedItemDTO ,
5961 FeaturedItemsDTO
6062} from '../../../src/collections/domain/dtos/FeaturedItemsDTO'
63+ import { CreateDatasetTemplateDTO } from '../../../src/collections/domain/dtos/CreateDatasetTemplateDTO'
64+ import { getDatasetTemplates } from '../../../src/datasets'
65+ import { deleteDatasetTemplateViaApi } from '../../testHelpers/datasets/datasetTemplatesHelper'
6166
6267describe ( 'CollectionsRepository' , ( ) => {
6368 const testCollectionAlias = 'collectionsRepositoryTestCollection'
@@ -2143,4 +2148,59 @@ describe('CollectionsRepository', () => {
21432148 await expect ( sut . getCollectionLinks ( invalidCollectionId ) ) . rejects . toThrow ( expectedError )
21442149 } )
21452150 } )
2151+
2152+ describe ( 'createDatasetTemplate' , ( ) => {
2153+ const templateDto : CreateDatasetTemplateDTO = {
2154+ name : 'CollectionsRepository template' ,
2155+ isDefault : true ,
2156+ fields : [
2157+ {
2158+ typeName : 'author' ,
2159+ typeClass : MetadataFieldTypeClass . Compound ,
2160+ multiple : true ,
2161+ value : [
2162+ {
2163+ authorName : {
2164+ typeName : 'authorName' ,
2165+ typeClass : MetadataFieldTypeClass . Primitive ,
2166+ value : 'Belicheck, Bill'
2167+ } ,
2168+ authorAffiliation : {
2169+ typeName : 'authorIdentifierScheme' ,
2170+ typeClass : MetadataFieldTypeClass . Primitive ,
2171+ value : 'ORCID'
2172+ }
2173+ }
2174+ ]
2175+ }
2176+ ] ,
2177+ instructions : [
2178+ {
2179+ instructionField : 'author' ,
2180+ instructionText : 'The author data'
2181+ }
2182+ ]
2183+ }
2184+ test ( 'should create a template in :root with provided JSON' , async ( ) => {
2185+ await createDatasetTemplate . execute ( templateDto )
2186+ const templates = await getDatasetTemplates . execute ( ':root' )
2187+
2188+ expect ( templates [ templates . length - 1 ] . name ) . toBe ( templateDto . name )
2189+ expect ( templates [ templates . length - 1 ] . isDefault ) . toBe ( templateDto . isDefault )
2190+ expect ( templates [ templates . length - 1 ] . instructions . length ) . toBe (
2191+ templateDto . instructions ?. length ?? 0
2192+ )
2193+
2194+ deleteDatasetTemplateViaApi ( templates [ templates . length - 1 ] . id )
2195+ } )
2196+
2197+ test ( 'should return error when creating a template with invalidCollectionAlias' , async ( ) => {
2198+ const expectedError = new WriteError (
2199+ `[404] Can't find dataverse with identifier='invalidCollectionAlias'`
2200+ )
2201+ await expect (
2202+ createDatasetTemplate . execute ( templateDto , 'invalidCollectionAlias' )
2203+ ) . rejects . toThrow ( expectedError )
2204+ } )
2205+ } )
21462206} )
0 commit comments