-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathtransform-space.test.ts
More file actions
74 lines (63 loc) · 2.46 KB
/
transform-space.test.ts
File metadata and controls
74 lines (63 loc) · 2.46 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
import { cloneDeep } from 'lodash'
import {
contentTypeMock,
entryMock,
assetMock,
localeMock,
webhookMock
} from 'contentful-batch-libs/test/mocks/'
import transformSpace from '../../../lib/transform/transform-space'
import { Resources, TransformedSourceData } from '../../../lib/types'
import { TagSysProps } from 'contentful-management'
import type { AssetProps, LocaleProps, WebhookProps } from 'contentful-management'
const tagMock = {
sys: ({
id: 'myTagId'
} as TagSysProps),
name: 'mytagname'
}
type ResourcesWithDoNotTouch = Resources & {
doNotTouch?: boolean;
}
type TransformedSourceDataWithDoNotTouch = TransformedSourceData & {
doNotTouch?: boolean;
}
const space: ResourcesWithDoNotTouch = {
contentTypes: [contentTypeMock],
entries: [entryMock],
assets: [assetMock as unknown as AssetProps],
locales: [localeMock as LocaleProps],
webhooks: [webhookMock as WebhookProps],
tags: [tagMock]
}
const destinationSpace = cloneDeep(space)
space.doNotTouch = true
test('applies transformers to give space data', () => {
const result = transformSpace(space, destinationSpace) as TransformedSourceDataWithDoNotTouch
expect(result.contentTypes[0]).toHaveProperty('original')
expect(result.contentTypes[0]).toHaveProperty('transformed')
expect(result.entries?.[0]).toHaveProperty('original')
expect(result.entries?.[0]).toHaveProperty('transformed')
expect(result.assets[0]).toHaveProperty('original')
expect(result.assets[0]).toHaveProperty('transformed')
expect(result.tags?.[0]).toHaveProperty('original')
expect(result.tags?.[0]).toHaveProperty('transformed')
expect(result.locales?.[0]).toHaveProperty('original')
expect(result.locales?.[0]).toHaveProperty('transformed')
expect(result.webhooks?.[0]).toHaveProperty('original')
expect(result.webhooks?.[0]).toHaveProperty('transformed')
expect(result.doNotTouch).toBe(true)
})
test('applies custom transformers to give space data', () => {
const result = transformSpace(space, destinationSpace, {
entries: () => 'transformed'
})
expect(result.entries?.[0]?.transformed).toBe('transformed')
})
test('applies transformers to given entity types', () => {
const result = transformSpace(space, destinationSpace, {}, ['entries'])
expect(result.contentTypes[0]).not.toHaveProperty('original')
expect(result.contentTypes[0]).not.toHaveProperty('transformed')
expect(result.entries[0]).toHaveProperty('original')
expect(result.entries[0]).toHaveProperty('transformed')
})