@@ -567,6 +567,55 @@ describe('CollectionsRepository', () => {
567567 } )
568568 } )
569569
570+ describe ( 'getCollectionsForLinking' , ( ) => {
571+ test ( 'should call dataverse variant with numeric id and search term' , async ( ) => {
572+ const payload = {
573+ data : {
574+ status : 'OK' ,
575+ data : [
576+ { id : 1 , alias : 'dv1' , name : 'DV 1' } ,
577+ { id : 2 , alias : 'dv2' , name : 'DV 2' }
578+ ]
579+ }
580+ }
581+ jest . spyOn ( axios , 'get' ) . mockResolvedValue ( payload )
582+
583+ const actual = await sut . getCollectionsForLinking ( 'collection' , 99 , 'abc' )
584+ const expectedEndpoint = `${ TestConstants . TEST_API_URL } /dataverses/99/dataverse/linkingDataverses`
585+ const expectedParams = new URLSearchParams ( { searchTerm : 'abc' } )
586+ const expectedConfig = {
587+ params : expectedParams ,
588+ headers : TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY . headers
589+ }
590+ expect ( axios . get ) . toHaveBeenCalledWith ( expectedEndpoint , expectedConfig )
591+ expect ( actual ) . toEqual ( [
592+ { id : 1 , alias : 'dv1' , displayName : 'DV 1' } ,
593+ { id : 2 , alias : 'dv2' , displayName : 'DV 2' }
594+ ] )
595+ } )
596+
597+ test ( 'should call dataset variant using persistentId and map results' , async ( ) => {
598+ const payload = {
599+ data : {
600+ status : 'OK' ,
601+ data : [ { id : 3 , alias : 'dv3' , name : 'DV 3' } ]
602+ }
603+ }
604+ jest . spyOn ( axios , 'get' ) . mockResolvedValue ( payload )
605+
606+ const pid = 'doi:10.5072/FK2/J8SJZB'
607+ const actual = await sut . getCollectionsForLinking ( 'dataset' , pid , '' )
608+ const expectedEndpoint = `${ TestConstants . TEST_API_URL } /dataverses/:persistentId/dataset/linkingDataverses`
609+ const expectedParams = new URLSearchParams ( { persistentId : pid } )
610+ const expectedConfig = {
611+ params : expectedParams ,
612+ headers : TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY . headers
613+ }
614+ expect ( axios . get ) . toHaveBeenCalledWith ( expectedEndpoint , expectedConfig )
615+ expect ( actual ) . toEqual ( [ { id : 3 , alias : 'dv3' , displayName : 'DV 3' } ] )
616+ } )
617+ } )
618+
570619 describe ( 'deleteCollection' , ( ) => {
571620 const deleteTestCollectionAlias = 'deleteCollection-unit-test'
572621 const deleteTestCollectionId = 123
0 commit comments