-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUpdateCollection.test.ts
More file actions
77 lines (71 loc) · 2.84 KB
/
UpdateCollection.test.ts
File metadata and controls
77 lines (71 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import {
ApiConfig,
WriteError,
createCollection,
getCollection,
updateCollection,
CollectionDTO
} from '../../../src'
import { TestConstants } from '../../testHelpers/TestConstants'
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
import { createCollectionDTO } from '../../testHelpers/collections/collectionHelper'
describe('execute', () => {
beforeEach(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
DataverseApiAuthMechanism.API_KEY,
process.env.TEST_API_KEY
)
})
test('should successfully update a new collection', async () => {
const testNewCollectionAlias = 'updateCollection-functional-test'
const testNewCollection = createCollectionDTO(testNewCollectionAlias)
await createCollection.execute(testNewCollection)
const testNewName = 'Updated Name'
testNewCollection.name = testNewName
expect.assertions(1)
try {
await updateCollection.execute(testNewCollectionAlias, testNewCollection)
} catch (error) {
throw new Error('Collection should be updated')
} finally {
const updatedCollection = await getCollection.execute(testNewCollectionAlias)
expect(updatedCollection.name).toBe(testNewName)
}
})
test('should successfully update a collection with partial data (name only)', async () => {
const testNewCollectionAlias = 'updateCollection-partial-test'
const testNewCollection = createCollectionDTO(testNewCollectionAlias)
await createCollection.execute(testNewCollection)
const partialUpdate: Partial<CollectionDTO> = {
name: 'Partially Updated Name'
}
expect.assertions(3)
try {
await updateCollection.execute(testNewCollectionAlias, partialUpdate)
} catch (error) {
throw new Error('Collection should be updated with partial data')
} finally {
const updatedCollection = await getCollection.execute(testNewCollectionAlias)
expect(updatedCollection.name).toBe('Partially Updated Name')
expect(updatedCollection.alias).toBe(testNewCollectionAlias)
expect(updatedCollection.type).toBe(testNewCollection.type)
}
})
test('should throw an error when the parent collection does not exist', async () => {
const testNewCollection = createCollectionDTO()
expect.assertions(2)
let writeError: WriteError | undefined = undefined
try {
await updateCollection.execute(TestConstants.TEST_DUMMY_COLLECTION_ID, testNewCollection)
throw new Error('Use case should throw an error')
} catch (error) {
writeError = error as WriteError
} finally {
expect(writeError).toBeInstanceOf(WriteError)
expect(writeError?.message).toEqual(
`There was an error when writing the resource. Reason was: [404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'`
)
}
})
})