|
| 1 | +import { ApiConfig, createCollection, publishCollection, WriteError } from '../../../src' |
| 2 | +import { TestConstants } from '../../testHelpers/TestConstants' |
| 3 | +import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig' |
| 4 | +import { |
| 5 | + createCollectionDTO, |
| 6 | + deleteCollectionViaApi |
| 7 | +} from '../../testHelpers/collections/collectionHelper' |
| 8 | + |
| 9 | +const testNewCollection = createCollectionDTO('test-publish-collection') |
| 10 | + |
| 11 | +describe('execute', () => { |
| 12 | + beforeEach(async () => { |
| 13 | + ApiConfig.init( |
| 14 | + TestConstants.TEST_API_URL, |
| 15 | + DataverseApiAuthMechanism.API_KEY, |
| 16 | + process.env.TEST_API_KEY |
| 17 | + ) |
| 18 | + }) |
| 19 | + |
| 20 | + test('should successfully publish a collection with id', async () => { |
| 21 | + const createdCollectiontIdentifier = await createCollection.execute(testNewCollection) |
| 22 | + |
| 23 | + const response = await publishCollection.execute(createdCollectiontIdentifier) |
| 24 | + |
| 25 | + expect(response).toBeUndefined() |
| 26 | + await deleteCollectionViaApi(testNewCollection.alias) |
| 27 | + }) |
| 28 | + test('should successfully publish a collection with alias', async () => { |
| 29 | + await createCollection.execute(testNewCollection) |
| 30 | + |
| 31 | + const response = await publishCollection.execute(testNewCollection.alias) |
| 32 | + |
| 33 | + expect(response).toBeUndefined() |
| 34 | + await deleteCollectionViaApi(testNewCollection.alias) |
| 35 | + }) |
| 36 | + |
| 37 | + test('should throw an error when trying to publish a collection that does not exist', async () => { |
| 38 | + const nonExistentTestCollectionId = 4567 |
| 39 | + const expectedError = new WriteError( |
| 40 | + `[404] Can't find dataverse with identifier='${nonExistentTestCollectionId}'` |
| 41 | + ) |
| 42 | + |
| 43 | + await expect(publishCollection.execute(nonExistentTestCollectionId)).rejects.toThrow( |
| 44 | + expectedError |
| 45 | + ) |
| 46 | + }) |
| 47 | +}) |
0 commit comments