@@ -569,4 +569,87 @@ describe('CollectionsRepository', () => {
569569 expect ( error ) . toBeInstanceOf ( Error )
570570 } )
571571 } )
572+
573+ describe ( 'deleteCollection' , ( ) => {
574+ const deleteTestCollectionAlias = 'deleteCollection-unit-test'
575+ const deleteTestCollectionId = 123
576+
577+ describe ( 'by numeric id' , ( ) => {
578+ const expectedApiEndpoint = `${ TestConstants . TEST_API_URL } /dataverses/${ deleteTestCollectionId } `
579+
580+ test ( 'should delete a collection when providing a valid id' , async ( ) => {
581+ jest . spyOn ( axios , 'delete' ) . mockResolvedValue ( { data : { status : 'OK' } } )
582+
583+ // API Key auth
584+ await sut . deleteCollection ( deleteTestCollectionId )
585+
586+ expect ( axios . delete ) . toHaveBeenCalledWith (
587+ expectedApiEndpoint ,
588+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY
589+ )
590+
591+ // Session cookie auth
592+ ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . SESSION_COOKIE )
593+
594+ await sut . deleteCollection ( deleteTestCollectionId )
595+
596+ expect ( axios . delete ) . toHaveBeenCalledWith (
597+ expectedApiEndpoint ,
598+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE
599+ )
600+ } )
601+
602+ test ( 'should return error result on error response' , async ( ) => {
603+ jest . spyOn ( axios , 'delete' ) . mockRejectedValue ( TestConstants . TEST_ERROR_RESPONSE )
604+
605+ let error = undefined as unknown as WriteError
606+ await sut . deleteCollection ( deleteTestCollectionId ) . catch ( ( e ) => ( error = e ) )
607+
608+ expect ( axios . delete ) . toHaveBeenCalledWith (
609+ expectedApiEndpoint ,
610+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY
611+ )
612+ expect ( error ) . toBeInstanceOf ( WriteError )
613+ } )
614+ } )
615+
616+ describe ( 'by alias id' , ( ) => {
617+ const expectedApiEndpoint = `${ TestConstants . TEST_API_URL } /dataverses/${ deleteTestCollectionAlias } `
618+
619+ test ( 'should delete a collection when providing a valid alias' , async ( ) => {
620+ jest . spyOn ( axios , 'delete' ) . mockResolvedValue ( { data : { status : 'OK' } } )
621+
622+ // API Key auth
623+ await sut . deleteCollection ( deleteTestCollectionAlias )
624+
625+ expect ( axios . delete ) . toHaveBeenCalledWith (
626+ expectedApiEndpoint ,
627+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY
628+ )
629+
630+ // Session cookie auth
631+ ApiConfig . init ( TestConstants . TEST_API_URL , DataverseApiAuthMechanism . SESSION_COOKIE )
632+
633+ await sut . deleteCollection ( deleteTestCollectionAlias )
634+
635+ expect ( axios . delete ) . toHaveBeenCalledWith (
636+ expectedApiEndpoint ,
637+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_SESSION_COOKIE
638+ )
639+ } )
640+
641+ test ( 'should return error result on error response' , async ( ) => {
642+ jest . spyOn ( axios , 'delete' ) . mockRejectedValue ( TestConstants . TEST_ERROR_RESPONSE )
643+
644+ let error = undefined as unknown as WriteError
645+ await sut . deleteCollection ( deleteTestCollectionAlias ) . catch ( ( e ) => ( error = e ) )
646+
647+ expect ( axios . delete ) . toHaveBeenCalledWith (
648+ expectedApiEndpoint ,
649+ TestConstants . TEST_EXPECTED_AUTHENTICATED_REQUEST_CONFIG_API_KEY
650+ )
651+ expect ( error ) . toBeInstanceOf ( WriteError )
652+ } )
653+ } )
654+ } )
572655} )
0 commit comments