@@ -42,9 +42,11 @@ import {
4242 setStorageDriverViaApi
4343} from '../../testHelpers/collections/collectionHelper'
4444import { RestrictFileDTO } from '../../../src/files/domain/dtos/RestrictFileDTO'
45+ import { DatasetsRepository } from '../../../src/datasets/infra/repositories/DatasetsRepository'
4546
4647describe ( 'FilesRepository' , ( ) => {
4748 const sut : FilesRepository = new FilesRepository ( )
49+ const sutDataset : DatasetsRepository = new DatasetsRepository ( )
4850
4951 let testDatasetIds : CreatedDatasetIdentifiers
5052
@@ -773,10 +775,7 @@ describe('FilesRepository', () => {
773775 termsOfAccess : 'This file is restricted for testing purposes'
774776 }
775777
776- const unrestrictFileDTO : RestrictFileDTO = {
777- restrict : false ,
778- termsOfAccess : 'This file is restricted for testing purposes'
779- }
778+ const unrestrictFileDTO : RestrictFileDTO = { restrict : false }
780779
781780 const setFileToRestricted = async ( fileId : number ) => {
782781 await sut . restrictFile ( fileId , restrictFileDTO )
@@ -797,11 +796,15 @@ describe('FilesRepository', () => {
797796 } )
798797 } )
799798
800- afterEach ( async ( ) => {
801- await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
802- } )
799+ test ( 'should successfully restrict a file enabling access request' , async ( ) => {
800+ await publishDatasetViaApi ( restrictFileDatasetIds . numericId ) . catch ( ( ) => {
801+ throw new Error ( 'Error while publishing test Dataset' )
802+ } )
803+
804+ await waitForNoLocks ( restrictFileDatasetIds . numericId , 10 ) . catch ( ( ) => {
805+ throw new Error ( 'Error while waiting for no locks' )
806+ } )
803807
804- test ( 'should successfully restrict a file' , async ( ) => {
805808 const datasetFiles = await sut . getDatasetFiles (
806809 restrictFileDatasetIds . numericId ,
807810 DatasetNotNumberedVersion . LATEST ,
@@ -820,10 +823,22 @@ describe('FilesRepository', () => {
820823 FileOrderCriteria . NAME_AZ
821824 )
822825
823- expect ( datasetFilesAfterRestrict . files [ 0 ] . restricted ) . toEqual ( true )
826+ expect ( datasetFilesAfterRestrict . files [ 0 ] . restricted ) . toEqual ( restrictFileDTO . restrict )
824827
825- // Unrestrict the file Just in case to avoid conflicts with other tests
826- await setFileToUnrestricted ( datasetFiles . files [ 0 ] . id )
828+ const dataset = await sutDataset . getDataset (
829+ restrictFileDatasetIds . numericId ,
830+ DatasetNotNumberedVersion . LATEST ,
831+ false ,
832+ false
833+ )
834+ expect ( datasetFilesAfterRestrict . files [ 0 ] . fileAccessRequest ) . toEqual (
835+ restrictFileDTO . enableAccessRequest
836+ )
837+ expect ( dataset . termsOfUse . termsOfAccess . termsOfAccessForRestrictedFiles ) . toEqual (
838+ restrictFileDTO . termsOfAccess
839+ )
840+
841+ await deletePublishedDatasetViaApi ( restrictFileDatasetIds . persistentId )
827842 } )
828843
829844 test ( 'should successfully unrestrict a file' , async ( ) => {
@@ -857,6 +872,8 @@ describe('FilesRepository', () => {
857872 )
858873
859874 expect ( datasetFilesAfterUnrestrict . files [ 0 ] . restricted ) . toEqual ( false )
875+
876+ await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
860877 } )
861878
862879 test ( 'should return error when file was already restricted' , async ( ) => {
@@ -877,6 +894,8 @@ describe('FilesRepository', () => {
877894
878895 // Unrestrict the file Just in case to avoid conflicts with other tests
879896 await setFileToUnrestricted ( datasetFiles . files [ 0 ] . id )
897+
898+ await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
880899 } )
881900
882901 test ( 'should return error when files was already unrestricted' , async ( ) => {
@@ -892,6 +911,8 @@ describe('FilesRepository', () => {
892911 )
893912
894913 await expect ( setFileToUnrestricted ( datasetFiles . files [ 0 ] . id ) ) . rejects . toThrow ( expectedError )
914+
915+ await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
895916 } )
896917
897918 test ( 'should return error when file does not exist' , async ( ) => {
@@ -900,6 +921,8 @@ describe('FilesRepository', () => {
900921 )
901922
902923 await expect ( setFileToRestricted ( nonExistentFiledId ) ) . rejects . toThrow ( expectedError )
924+
925+ await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
903926 } )
904927
905928 test ( 'should return error when the terms of use is empty while enableAccess is false' , async ( ) => {
@@ -920,6 +943,8 @@ describe('FilesRepository', () => {
920943 enableAccessRequest : false
921944 } )
922945 ) . rejects . toThrow ( errorExpected )
946+
947+ await deleteUnpublishedDatasetViaApi ( restrictFileDatasetIds . numericId )
923948 } )
924949 } )
925950} )
0 commit comments