@@ -819,7 +819,8 @@ describe('CollectionsRepository', () => {
819819 const results = await sut . getCollectionsForLinking (
820820 'collection' ,
821821 testCollectionAlias ,
822- 'Scientific'
822+ 'Scientific' ,
823+ false
823824 )
824825
825826 expect ( Array . isArray ( results ) ) . toBe ( true )
@@ -837,7 +838,12 @@ describe('CollectionsRepository', () => {
837838 testCollectionAlias
838839 )
839840
840- const results = await sut . getCollectionsForLinking ( 'dataset' , persistentId , 'Scientific' )
841+ const results = await sut . getCollectionsForLinking (
842+ 'dataset' ,
843+ persistentId ,
844+ 'Scientific' ,
845+ false
846+ )
841847
842848 // Cleanup dataset (unpublished)
843849 await deleteUnpublishedDatasetViaApi ( numericId )
@@ -848,15 +854,44 @@ describe('CollectionsRepository', () => {
848854 expect ( found ?. displayName ) . toBe ( 'Scientific Research' )
849855 } )
850856
857+ test ( 'should return collections for unlking when sending alreadyLinked param to true' , async ( ) => {
858+ // Link the test collection with the linking target collection
859+ await sut . linkCollection ( testCollectionAlias , linkingTargetAlias )
860+
861+ const collectionsForLinking = await sut . getCollectionsForLinking (
862+ 'collection' ,
863+ testCollectionAlias ,
864+ '' ,
865+ false
866+ )
867+
868+ const collectionsForUnlinking = await sut . getCollectionsForLinking (
869+ 'collection' ,
870+ testCollectionAlias ,
871+ '' ,
872+ true
873+ )
874+
875+ expect ( collectionsForLinking . length ) . toBe ( 0 )
876+ expect ( collectionsForUnlinking . length ) . toBeGreaterThan ( 0 )
877+ expect ( collectionsForUnlinking [ 0 ] . alias ) . toBe ( linkingTargetAlias )
878+ expect ( collectionsForUnlinking [ 0 ] . displayName ) . toBe ( 'Scientific Research' )
879+ } )
880+
851881 it ( 'should return error when collection does not exist' , async ( ) => {
852882 await expect (
853- sut . getCollectionsForLinking ( 'collection' , TestConstants . TEST_DUMMY_COLLECTION_ALIAS , '' )
883+ sut . getCollectionsForLinking (
884+ 'collection' ,
885+ TestConstants . TEST_DUMMY_COLLECTION_ALIAS ,
886+ '' ,
887+ false
888+ )
854889 ) . rejects . toThrow ( ReadError )
855890 } )
856891
857892 it ( 'should return error when dataset does not exist' , async ( ) => {
858893 await expect (
859- sut . getCollectionsForLinking ( 'dataset' , TestConstants . TEST_DUMMY_PERSISTENT_ID , '' )
894+ sut . getCollectionsForLinking ( 'dataset' , TestConstants . TEST_DUMMY_PERSISTENT_ID , '' , false )
860895 ) . rejects . toThrow ( ReadError )
861896 } )
862897 } )
0 commit comments