-
Notifications
You must be signed in to change notification settings - Fork 66.6k
Expand file tree
/
Copy pathrendering.ts
More file actions
142 lines (123 loc) · 4.61 KB
/
rendering.ts
File metadata and controls
142 lines (123 loc) · 4.61 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { readFile } from 'fs/promises'
import { describe, expect, test, vi } from 'vitest'
import { allVersions } from '@/versions/lib/all-versions'
import { get, getDOM } from '@/tests/helpers/e2etest'
import { categoriesWithoutSubcategories } from '@/rest/lib/index'
import { getAppsData } from '@/github-apps/lib/index'
import type { Version } from '@/types'
interface PageConfig {
frontmatterDefaults: {
versions: string | Record<string, string>
autogenerated: string
}
targetFilename: string
}
interface AppsConfig {
targetDirectory: string
pages: Record<string, PageConfig>
'api-versions': Record<string, string[]>
sha: string
}
interface PermissionItem {
category: string
subcategory: string
slug: string
}
interface PermissionData {
permissions: PermissionItem[]
}
interface EnabledItem {
subcategory: string
slug: string
}
const configContent: AppsConfig = JSON.parse(
await readFile('src/github-apps/lib/config.json', 'utf8'),
)
const pageTypes: string[] = Object.keys(configContent.pages)
const permissionPages: string[] = pageTypes.filter((pageType) => pageType.includes('permissions'))
const enabledPages: string[] = pageTypes.filter((pageType) => !pageType.includes('permissions'))
const defaultVersion: Version | undefined = Object.values(allVersions)
.filter((version) => version.nonEnterpriseDefault)
.shift()
if (!defaultVersion) {
throw new Error('No default version found')
}
const version: string = defaultVersion.version
const apiVersion: string = defaultVersion.latestApiVersion
describe('REST references docs', () => {
vi.setConfig({ testTimeout: 3 * 60 * 1000 })
// This test ensures that the page component and the Markdown file are
// in sync. It also checks that all expected items are present.
// For every version of /rest/overview/endpoints-available-for-github-apps
test('loads enabled list pages', async () => {
for (const page of enabledPages) {
const schemaSlugs: string[] = []
const enabledForApps: Record<string, EnabledItem[]> = await getAppsData(
page,
version,
apiVersion,
)
// using the static file, generate the expected slug for each operation
for (const [key, value] of Object.entries(enabledForApps)) {
schemaSlugs.push(
...value.map(
(item: EnabledItem) =>
`/en/rest/${key}${
categoriesWithoutSubcategories.includes(key) ? '' : `/${item.subcategory}`
}#${item.slug}`,
),
)
}
// get all of the href attributes in the anchor tags
const contentPath = configContent.pages[page].targetFilename
.replace('content/', '')
.replace('.md', '')
const $ = await getDOM(`/en/${contentPath}${apiVersion ? `?apiVersion=${apiVersion}` : ''}`)
const domH3Ids = $('#article-contents a')
.map((i, a) => $(a).attr('href'))
.get()
expect(schemaSlugs.every((slug) => domH3Ids.includes(slug))).toBe(true)
}
})
test('loads permission list pages', async () => {
// permissions pages
for (const page of permissionPages) {
const schemaSlugs: string[] = []
const permissionsData: Record<string, PermissionData> = await getAppsData(
page,
version,
apiVersion,
)
// using the static file, generate the expected slug for each operation
for (const value of Object.values(permissionsData)) {
schemaSlugs.push(
...value.permissions.map(
(item: PermissionItem) =>
`/en/rest/${item.category}${
categoriesWithoutSubcategories.includes(item.category) ? '' : `/${item.subcategory}`
}#${item.slug}`,
),
)
}
// get all of the href attributes in the anchor tags
const contentPath = configContent.pages[page].targetFilename
.replace('content/', '')
.replace('.md', '')
const $ = await getDOM(`/en/${contentPath}${apiVersion ? `?apiVersion=${apiVersion}` : ''}`)
const domH3Ids = $('#article-contents table tbody tr td a')
.map((i, a) => $(a).attr('href'))
.get()
expect(schemaSlugs.every((slug) => domH3Ids.includes(slug))).toBe(true)
}
})
for (const page of pageTypes) {
const contentPath = configContent.pages[page].targetFilename
.replace('content/', '')
.replace('.md', '')
const url = `/${contentPath}?${new URLSearchParams({ apiVersion: 'junk' })}`
test(`falls back when unsupported calendar version provided for ${contentPath}`, async () => {
const res = await get(url, { followRedirects: true })
expect(res.statusCode).toBe(200)
})
}
})