-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathgenerate-docs.test.ts
More file actions
79 lines (71 loc) · 2.47 KB
/
Copy pathgenerate-docs.test.ts
File metadata and controls
79 lines (71 loc) · 2.47 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
78
79
import { describe, expect, it } from 'vitest'
import { parseConstProperties, parsePropertiesContent } from './generate-docs'
describe('documentation output property parsing', () => {
it('keeps a response field named items inside an array element', () => {
const properties = parsePropertiesContent(`
vaults: {
type: 'array',
description: 'List of accessible vaults',
items: {
type: 'object',
properties: {
id: { type: 'string', description: 'Vault ID' },
items: { type: 'number', description: 'Number of items in the vault' },
},
},
},
`)
expect(Object.keys(properties)).toEqual(['vaults'])
expect(properties.vaults.items.properties.items).toEqual({
type: 'number',
description: 'Number of items in the vault',
})
})
it('keeps a response field named items that directly references a constant', () => {
const properties = parsePropertiesContent('items: ATTENDEES_OUTPUT,', 'calcom')
expect(properties.items).toMatchObject({
type: 'array',
description: 'List of attendees',
})
})
it('keeps a response field named items that references a constant property', () => {
const properties = parsePropertiesContent('items: EVENT_TYPE_OUTPUT_PROPERTIES.id,', 'calcom')
expect(properties.items).toEqual({
type: 'number',
description: 'Event type ID',
})
})
it('keeps items fields in constant-defined property maps', () => {
const typesContent = `
export const RECORD_OUTPUT_PROPERTIES = {
id: { type: 'string', description: 'Record ID' },
}
`
const properties = parseConstProperties(
`
items: {
type: 'object',
description: 'Result page',
properties: {
object: { type: 'string', description: 'Page type' },
data: {
type: 'array',
description: 'Result records',
items: { type: 'object', properties: RECORD_OUTPUT_PROPERTIES },
},
hasMore: { type: 'boolean', description: 'Whether more results exist' },
},
},
`,
'test',
typesContent,
0
)
expect(Object.keys(properties)).toEqual(['items'])
expect(Object.keys(properties.items.properties)).toEqual(['object', 'data', 'hasMore'])
expect(properties.items.properties.data.items.properties.id).toEqual({
type: 'string',
description: 'Record ID',
})
})
})