Skip to content

Commit 9b71a65

Browse files
authored
move github-app tests to feature directory (github#36040)
1 parent 84dc08e commit 9b71a65

2 files changed

Lines changed: 85 additions & 80 deletions

File tree

src/github-apps/tests/rendering.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { jest, test } from '@jest/globals'
2+
3+
import { get, getDOM } from '../../../tests/helpers/e2etest.js'
4+
import { categoriesWithoutSubcategories } from '../../rest/lib/index.js'
5+
import { getEnabledForApps } from '../lib/index.js'
6+
import { isApiVersioned, allVersions } from '../../../lib/all-versions.js'
7+
8+
describe('REST references docs', () => {
9+
jest.setTimeout(3 * 60 * 1000)
10+
11+
// Checks every version of the
12+
// /rest/overview/endpoints-available-for-github-apps page
13+
// and ensures that all sections in the openapi schema
14+
// are present in the page.
15+
test('loads operations enabled for GitHub Apps', async () => {
16+
const flatMapping = getFlatMappingWithCalendarDates()
17+
18+
for (const [version, versionValue] of Object.entries(flatMapping)) {
19+
const schemaSlugs = []
20+
const enabledForApps = await getEnabledForApps(version, versionValue.apiVersion)
21+
22+
// using the static file, generate the expected slug for each operation
23+
for (const [key, value] of Object.entries(enabledForApps)) {
24+
schemaSlugs.push(
25+
...value.map(
26+
(item) =>
27+
`/en${
28+
versionValue.url === '' ? versionValue.url : `/${versionValue.url}`
29+
}/rest/${key}${
30+
categoriesWithoutSubcategories.includes(key) ? '' : '/' + item.subcategory
31+
}#${item.slug}`
32+
)
33+
)
34+
}
35+
// get all of the href attributes in the anchor tags
36+
const $ = await getDOM(
37+
`/en/${versionValue.url}/rest/overview/endpoints-available-for-github-apps${
38+
versionValue.apiVersion ? `?apiVersion=${versionValue.apiVersion}` : ''
39+
}`
40+
)
41+
const domH3Ids = $('#article-contents a')
42+
.map((i, a) => $(a).attr('href'))
43+
.get()
44+
expect(schemaSlugs.every((slug) => domH3Ids.includes(slug))).toBe(true)
45+
}
46+
})
47+
48+
test('falls back when unsupported calendar version provided', async () => {
49+
const res = await get(
50+
`/en/rest/overview/endpoints-available-for-github-apps?${new URLSearchParams({
51+
apiVersion: 'junk',
52+
})}`
53+
)
54+
expect(res.statusCode).toBe(200)
55+
})
56+
})
57+
58+
// This gets a flat mapping for all REST versions (versioned and unversioned) and creates a mapping between
59+
// the full name of the version including calendar dates to its url name and apiVersion if it exists.
60+
// Example:
61+
// {
62+
// free-pro-team@latest: { url: '', apiVersion: 2022-08-09 }
63+
// free-pro-team@latest: { url: '', apiVersion: 2022-11-14 }
64+
// enterprise-cloud@latest: { url: 'enterprise-cloud@latest, apiVersion: 2022-11-14 }
65+
// enterprise-server@3.6: { url: enterprise-server@3.6 }
66+
// }
67+
function getFlatMappingWithCalendarDates() {
68+
const flatMapping = {}
69+
70+
for (const version in allVersions) {
71+
if (isApiVersioned(version)) {
72+
for (const apiVersion of allVersions[version].apiVersions) {
73+
flatMapping[allVersions[version].version] = {
74+
url: `${version === 'free-pro-team@latest' ? '' : allVersions[version].version}`,
75+
apiVersion,
76+
}
77+
}
78+
} else {
79+
flatMapping[allVersions[version].version] = { url: allVersions[version].version }
80+
}
81+
}
82+
83+
return flatMapping
84+
}

tests/rendering/rest.js

Lines changed: 1 addition & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { readdirSync, readFileSync } from 'fs'
44
import path from 'path'
55

66
import { get, getDOM } from '../helpers/e2etest.js'
7-
import getRest, {
8-
categoriesWithoutSubcategories,
9-
REST_DATA_DIR,
10-
REST_SCHEMA_FILENAME,
11-
} from '../../src/rest/lib/index.js'
12-
import { getEnabledForApps } from '../../src/github-apps/lib/index.js'
7+
import getRest, { REST_DATA_DIR, REST_SCHEMA_FILENAME } from '../../src/rest/lib/index.js'
138
import { isApiVersioned, allVersions } from '../../lib/all-versions.js'
149
import { getDiffOpenAPIContentRest } from '../../src/rest/scripts/test-open-api-schema.js'
1510

@@ -65,52 +60,6 @@ describe('REST references docs', () => {
6560
}
6661
})
6762

68-
// Checks every version of the
69-
// /rest/overview/endpoints-available-for-github-apps page
70-
// and ensures that all sections in the openapi schema
71-
// are present in the page.
72-
test('loads operations enabled for GitHub Apps', async () => {
73-
const flatMapping = getFlatMappingWithCalendarDates()
74-
75-
for (const [version, versionValue] of Object.entries(flatMapping)) {
76-
const schemaSlugs = []
77-
const enabledForApps = await getEnabledForApps(version, versionValue.apiVersion)
78-
79-
// using the static file, generate the expected slug for each operation
80-
for (const [key, value] of Object.entries(enabledForApps)) {
81-
schemaSlugs.push(
82-
...value.map(
83-
(item) =>
84-
`/en${
85-
versionValue.url === '' ? versionValue.url : `/${versionValue.url}`
86-
}/rest/${key}${
87-
categoriesWithoutSubcategories.includes(key) ? '' : '/' + item.subcategory
88-
}#${item.slug}`
89-
)
90-
)
91-
}
92-
// get all of the href attributes in the anchor tags
93-
const $ = await getDOM(
94-
`/en/${versionValue.url}/rest/overview/endpoints-available-for-github-apps${
95-
versionValue.apiVersion ? `?apiVersion=${versionValue.apiVersion}` : ''
96-
}`
97-
)
98-
const domH3Ids = $('#article-contents a')
99-
.map((i, a) => $(a).attr('href'))
100-
.get()
101-
expect(schemaSlugs.every((slug) => domH3Ids.includes(slug))).toBe(true)
102-
}
103-
})
104-
105-
test('falls back when unsupported calendar version provided', async () => {
106-
const res = await get(
107-
`/en/rest/overview/endpoints-available-for-github-apps?${new URLSearchParams({
108-
apiVersion: 'junk',
109-
})}`
110-
)
111-
expect(res.statusCode).toBe(200)
112-
})
113-
11463
test('test the latest version of the OpenAPI schema categories/subcategories to see if it matches the content/rest directory', async () => {
11564
const differences = await getDiffOpenAPIContentRest()
11665
const errorMessage = formatErrors(differences)
@@ -175,31 +124,3 @@ If you come across this error in an Update OpenAPI Descriptions PR it's likely t
175124
If you have any questions contact #docs-engineering, #docs-content, or #docs-apis-and-events if you need help.`
176125
return errorMessage
177126
}
178-
179-
// This gets a flat mapping for all REST versions (versioned and unversioned) and creates a mapping between
180-
// the full name of the version including calendar dates to its url name and apiVersion if it exists.
181-
// Example:
182-
// {
183-
// free-pro-team@latest: { url: '', apiVersion: 2022-08-09 }
184-
// free-pro-team@latest: { url: '', apiVersion: 2022-11-14 }
185-
// enterprise-cloud@latest: { url: 'enterprise-cloud@latest, apiVersion: 2022-11-14 }
186-
// enterprise-server@3.6: { url: enterprise-server@3.6 }
187-
// }
188-
function getFlatMappingWithCalendarDates() {
189-
const flatMapping = {}
190-
191-
for (const version in allVersions) {
192-
if (isApiVersioned(version)) {
193-
for (const apiVersion of allVersions[version].apiVersions) {
194-
flatMapping[allVersions[version].version] = {
195-
url: `${version === 'free-pro-team@latest' ? '' : allVersions[version].version}`,
196-
apiVersion,
197-
}
198-
}
199-
} else {
200-
flatMapping[allVersions[version].version] = { url: allVersions[version].version }
201-
}
202-
}
203-
204-
return flatMapping
205-
}

0 commit comments

Comments
 (0)