Skip to content

Commit 78331c0

Browse files
committed
Added: UpdateCollection functional test
1 parent 08a0f06 commit 78331c0

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { ApiConfig, WriteError, createCollection, getCollection, updateCollection } from '../../../src'
2+
import { TestConstants } from '../../testHelpers/TestConstants'
3+
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
4+
import { createCollectionDTO } from '../../testHelpers/collections/collectionHelper'
5+
6+
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+
})
14+
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+
})
31+
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+
})
48+
})

0 commit comments

Comments
 (0)