|
| 1 | +import { SetDefaultContributorRole } from '../../../src/collections/domain/useCases/SetDefaultContributorRole' |
| 2 | +import { CollectionsRepository } from '../../../src/collections/infra/repositories/CollectionsRepository' |
| 3 | +import { ApiConfig } from '../../../src' |
| 4 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 5 | +import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
| 6 | +import { |
| 7 | + createCollectionViaApi, |
| 8 | + deleteCollectionViaApi |
| 9 | +} from '../../testHelpers/collections/collectionHelper' |
| 10 | +import { RoleAlias } from '../../../src/roles/domain/models/RoleAlias' |
| 11 | +import { WriteError } from '../../../src/core/domain/repositories/WriteError' |
| 12 | + |
| 13 | +describe('SetDefaultContributorRole', () => { |
| 14 | + const collectionsRepository = new CollectionsRepository() |
| 15 | + const useCase = new SetDefaultContributorRole(collectionsRepository) |
| 16 | + const testCollectionAlias = 'setDefaultContributorRoleTestCollection' |
| 17 | + |
| 18 | + beforeAll(async () => { |
| 19 | + ApiConfig.init( |
| 20 | + TestConstants.TEST_API_URL, |
| 21 | + DataverseApiAuthMechanism.API_KEY, |
| 22 | + process.env.TEST_API_KEY |
| 23 | + ) |
| 24 | + await createCollectionViaApi(testCollectionAlias) |
| 25 | + }) |
| 26 | + |
| 27 | + afterAll(async () => { |
| 28 | + await deleteCollectionViaApi(testCollectionAlias) |
| 29 | + }) |
| 30 | + |
| 31 | + test('should successfully set the default contributor role', async () => { |
| 32 | + const roleAlias = RoleAlias.CURATOR |
| 33 | + |
| 34 | + await expect(useCase.execute(testCollectionAlias, roleAlias)).resolves.toBeUndefined() |
| 35 | + }) |
| 36 | + |
| 37 | + test('should successfully set the default contributor role for the root collection', async () => { |
| 38 | + const roleAlias = RoleAlias.CURATOR |
| 39 | + |
| 40 | + await expect(useCase.execute(undefined, roleAlias)).resolves.toBeUndefined() |
| 41 | + }) |
| 42 | + |
| 43 | + test('should throw an error when the collection does not exist', async () => { |
| 44 | + const nonExistentCollection = 'nonExistentCollection' |
| 45 | + const roleAlias = RoleAlias.CURATOR |
| 46 | + |
| 47 | + await expect(useCase.execute(nonExistentCollection, roleAlias)).rejects.toThrow(WriteError) |
| 48 | + }) |
| 49 | + |
| 50 | + test('should throw an error when the role alias does not exist', async () => { |
| 51 | + const nonExistentRoleAlias = 'invalidRoleAlias' |
| 52 | + |
| 53 | + await expect(useCase.execute(testCollectionAlias, nonExistentRoleAlias)).rejects.toThrow( |
| 54 | + WriteError |
| 55 | + ) |
| 56 | + }) |
| 57 | +}) |
0 commit comments