|
1 |
| -import { ApiConfig, WriteError, createCollection, getCollection, updateCollection } from '../../../src' |
| 1 | +import { |
| 2 | + ApiConfig, |
| 3 | + WriteError, |
| 4 | + createCollection, |
| 5 | + getCollection, |
| 6 | + updateCollection |
| 7 | +} from '../../../src' |
2 | 8 | import { TestConstants } from '../../testHelpers/TestConstants'
|
3 | 9 | import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
|
4 | 10 | import { createCollectionDTO } from '../../testHelpers/collections/collectionHelper'
|
5 | 11 |
|
6 | 12 | describe('execute', () => {
|
7 |
| - beforeEach(async () => { |
8 |
| - ApiConfig.init( |
9 |
| - TestConstants.TEST_API_URL, |
10 |
| - DataverseApiAuthMechanism.API_KEY, |
11 |
| - process.env.TEST_API_KEY |
12 |
| - ) |
13 |
| - }) |
| 13 | + beforeEach(async () => { |
| 14 | + ApiConfig.init( |
| 15 | + TestConstants.TEST_API_URL, |
| 16 | + DataverseApiAuthMechanism.API_KEY, |
| 17 | + process.env.TEST_API_KEY |
| 18 | + ) |
| 19 | + }) |
14 | 20 |
|
15 |
| - test('should successfully update a new collection', async () => { |
16 |
| - const testNewCollectionAlias = 'updateCollection-functional-test' |
17 |
| - const testNewCollection = createCollectionDTO(testNewCollectionAlias) |
18 |
| - await createCollection.execute(testNewCollection) |
19 |
| - const testNewName = 'Updated Name' |
20 |
| - testNewCollection.name = testNewName |
21 |
| - expect.assertions(1) |
22 |
| - try { |
23 |
| - await updateCollection.execute(testNewCollectionAlias, testNewCollection) |
24 |
| - } catch (error) { |
25 |
| - throw new Error('Collection should be updated') |
26 |
| - } finally { |
27 |
| - const updatedCollection = await getCollection.execute(testNewCollectionAlias) |
28 |
| - expect(updatedCollection.name).toBe(testNewName) |
29 |
| - } |
30 |
| - }) |
| 21 | + test('should successfully update a new collection', async () => { |
| 22 | + const testNewCollectionAlias = 'updateCollection-functional-test' |
| 23 | + const testNewCollection = createCollectionDTO(testNewCollectionAlias) |
| 24 | + await createCollection.execute(testNewCollection) |
| 25 | + const testNewName = 'Updated Name' |
| 26 | + testNewCollection.name = testNewName |
| 27 | + expect.assertions(1) |
| 28 | + try { |
| 29 | + await updateCollection.execute(testNewCollectionAlias, testNewCollection) |
| 30 | + } catch (error) { |
| 31 | + throw new Error('Collection should be updated') |
| 32 | + } finally { |
| 33 | + const updatedCollection = await getCollection.execute(testNewCollectionAlias) |
| 34 | + expect(updatedCollection.name).toBe(testNewName) |
| 35 | + } |
| 36 | + }) |
31 | 37 |
|
32 |
| - test('should throw an error when the parent collection does not exist', async () => { |
33 |
| - const testNewCollection = createCollectionDTO() |
34 |
| - expect.assertions(2) |
35 |
| - let writeError: WriteError |
36 |
| - try { |
37 |
| - await updateCollection.execute(TestConstants.TEST_DUMMY_COLLECTION_ID, testNewCollection) |
38 |
| - throw new Error('Use case should throw an error') |
39 |
| - } catch (error) { |
40 |
| - writeError = error |
41 |
| - } finally { |
42 |
| - expect(writeError).toBeInstanceOf(WriteError) |
43 |
| - expect(writeError.message).toEqual( |
44 |
| - `There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'` |
45 |
| - ) |
46 |
| - } |
47 |
| - }) |
| 38 | + test('should throw an error when the parent collection does not exist', async () => { |
| 39 | + const testNewCollection = createCollectionDTO() |
| 40 | + expect.assertions(2) |
| 41 | + let writeError: WriteError |
| 42 | + try { |
| 43 | + await updateCollection.execute(TestConstants.TEST_DUMMY_COLLECTION_ID, testNewCollection) |
| 44 | + throw new Error('Use case should throw an error') |
| 45 | + } catch (error) { |
| 46 | + writeError = error |
| 47 | + } finally { |
| 48 | + expect(writeError).toBeInstanceOf(WriteError) |
| 49 | + expect(writeError.message).toEqual( |
| 50 | + `There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'` |
| 51 | + ) |
| 52 | + } |
| 53 | + }) |
48 | 54 | })
|
0 commit comments