|
| 1 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 2 | +import { |
| 3 | + ApiConfig, |
| 4 | + DataverseApiAuthMechanism |
| 5 | +} from '../../../src/core/infra/repositories/ApiConfig' |
| 6 | +import { |
| 7 | + createDataset, |
| 8 | + DatasetNotNumberedVersion, |
| 9 | + getDataset, |
| 10 | + updateTermsOfAccess |
| 11 | +} from '../../../src/datasets' |
| 12 | +import { WriteError } from '../../../src' |
| 13 | + |
| 14 | +describe('UpdateTermsOfAccess (functional)', () => { |
| 15 | + beforeAll(() => { |
| 16 | + ApiConfig.init( |
| 17 | + TestConstants.TEST_API_URL, |
| 18 | + DataverseApiAuthMechanism.API_KEY, |
| 19 | + process.env.TEST_API_KEY |
| 20 | + ) |
| 21 | + }) |
| 22 | + |
| 23 | + test('should update terms of access with provided fields', async () => { |
| 24 | + const ids = await createDataset.execute(TestConstants.TEST_NEW_DATASET_DTO) |
| 25 | + |
| 26 | + await updateTermsOfAccess.execute(ids.numericId, { |
| 27 | + fileAccessRequest: true, |
| 28 | + termsOfAccessForRestrictedFiles: 'Your terms', |
| 29 | + dataAccessPlace: 'Place' |
| 30 | + }) |
| 31 | + |
| 32 | + const dataset = await getDataset.execute( |
| 33 | + ids.numericId, |
| 34 | + DatasetNotNumberedVersion.LATEST, |
| 35 | + false, |
| 36 | + false |
| 37 | + ) |
| 38 | + |
| 39 | + expect(dataset.termsOfUse.termsOfAccess.fileAccessRequest).toBe(true) |
| 40 | + expect(dataset.termsOfUse.termsOfAccess.termsOfAccessForRestrictedFiles).toBe('Your terms') |
| 41 | + expect(dataset.termsOfUse.termsOfAccess.dataAccessPlace).toBe('Place') |
| 42 | + }) |
| 43 | + |
| 44 | + test('should throw when dataset does not exist', async () => { |
| 45 | + await expect( |
| 46 | + updateTermsOfAccess.execute(999999, { |
| 47 | + fileAccessRequest: false |
| 48 | + }) |
| 49 | + ).rejects.toBeInstanceOf(WriteError) |
| 50 | + }) |
| 51 | +}) |
0 commit comments