|
4 | 4 | CreatedDatasetIdentifiers, |
5 | 5 | restrictFile, |
6 | 6 | getDatasetFiles, |
7 | | - WriteError |
| 7 | + WriteError, |
| 8 | + getDataset |
8 | 9 | } from '../../../src' |
9 | 10 | import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
10 | 11 | import { |
@@ -69,6 +70,32 @@ describe('execute', () => { |
69 | 70 | } |
70 | 71 | }) |
71 | 72 |
|
| 73 | + test('should successfully restrict a file with terms of use', async () => { |
| 74 | + try { |
| 75 | + const datasetFiles = await getDatasetFiles.execute(testDatasetIds.numericId) |
| 76 | + |
| 77 | + await restrictFile.execute(datasetFiles.files[0].id, { |
| 78 | + restrict: true, |
| 79 | + enableAccessRequest: false, |
| 80 | + termsOfAccess: 'This file is restricted for testing purposes' |
| 81 | + }) |
| 82 | + } catch (error) { |
| 83 | + throw new Error('File should be restricted') |
| 84 | + } finally { |
| 85 | + const datasetFilesAfterRestriction = await getDatasetFiles.execute(testDatasetIds.numericId) |
| 86 | + |
| 87 | + expect(datasetFilesAfterRestriction.files[0].restricted).toEqual(true) |
| 88 | + |
| 89 | + const dataset = await getDataset.execute(testDatasetIds.numericId) |
| 90 | + |
| 91 | + expect(dataset.termsOfUse.termsOfAccess.termsOfAccessForRestrictedFiles).toEqual( |
| 92 | + 'This file is restricted for testing purposes' |
| 93 | + ) |
| 94 | + |
| 95 | + await restrictFile.execute(datasetFilesAfterRestriction.files[0].id, { restrict: false }) |
| 96 | + } |
| 97 | + }) |
| 98 | + |
72 | 99 | test('should succesfully unrestrict a file', async () => { |
73 | 100 | try { |
74 | 101 | const datasetFiles = await getDatasetFiles.execute(testDatasetIds.numericId) |
@@ -124,7 +151,8 @@ describe('execute', () => { |
124 | 151 |
|
125 | 152 | expect(caughtError).toBeInstanceOf(WriteError) |
126 | 153 | expect((caughtError as WriteError).message).toEqual( |
127 | | - 'There was an error when writing the resource. Reason was: [409] Terms of Use and Access are invalid. You must enable request access or add terms of access in datasets with restricted files.' |
| 154 | + new WriteError().message + |
| 155 | + ' Reason was: [409] Terms of Use and Access are invalid. You must enable request access or add terms of access in datasets with restricted files.' |
128 | 156 | ) |
129 | 157 | }) |
130 | 158 | }) |
0 commit comments