-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathDeleteCollectionFeaturedItem.test.ts
More file actions
70 lines (62 loc) · 2.31 KB
/
Copy pathDeleteCollectionFeaturedItem.test.ts
File metadata and controls
70 lines (62 loc) · 2.31 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
import { ApiConfig, deleteCollectionFeaturedItem, WriteError } from '../../../src'
import { TestConstants } from '../../testHelpers/TestConstants'
import { DataverseApiAuthMechanism } from '../../../src/core/infra/repositories/ApiConfig'
import {
createCollectionViaApi,
deleteCollectionViaApi
} from '../../testHelpers/collections/collectionHelper'
import { createCollectionCustomFeaturedItemViaApi } from '../../testHelpers/collections/collectionFeaturedItemsHelper'
describe('execute', () => {
const testCollectionAlias = 'deleteCollectionFeaturedItemTest'
let featuredItemTestId: number
beforeEach(async () => {
ApiConfig.init(
TestConstants.TEST_API_URL,
DataverseApiAuthMechanism.API_KEY,
process.env.TEST_API_KEY
)
})
beforeAll(async () => {
try {
await createCollectionViaApi(testCollectionAlias)
const featuredItem = await createCollectionCustomFeaturedItemViaApi(testCollectionAlias, {
content: '<p class="rte-paragraph">Test content</p>',
displayOrder: 1,
withFile: true,
fileName: 'featured-item-test-image.png'
})
featuredItemTestId = featuredItem.id
} catch (error) {
throw new Error(
`Tests beforeAll(): Error while creating test collection: ${testCollectionAlias}`
)
}
})
afterAll(async () => {
try {
await deleteCollectionViaApi(testCollectionAlias)
} catch (error) {
throw new Error(
`Tests afterAll(): Error while deleting test collection: ${testCollectionAlias}`
)
}
})
test('should succesfully delete the featured item', async () => {
const actual = await deleteCollectionFeaturedItem.execute(featuredItemTestId)
expect(actual).toBeUndefined()
})
test('should throw an error when featured item does not exist', async () => {
const invalidFeaturedItemId = 99
let writeError: WriteError | undefined
try {
await deleteCollectionFeaturedItem.execute(invalidFeaturedItemId)
} catch (error) {
writeError = error as WriteError
} finally {
expect(writeError).toBeInstanceOf(WriteError)
expect((writeError as WriteError).message).toEqual(
`There was an error when writing the resource. Reason was: [404] Could not find dataverse featured item with identifier ${invalidFeaturedItemId}`
)
}
})
})