forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhooks.js
More file actions
115 lines (98 loc) · 4.47 KB
/
webhooks.js
File metadata and controls
115 lines (98 loc) · 4.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
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
import { jest } from '@jest/globals'
import { getDOM } from '../helpers/e2etest.js'
import { allVersions } from '../../lib/all-versions.js'
import { getWebhooks } from '../../src/webhooks/lib/index.js'
describe('webhooks events and payloads', () => {
jest.setTimeout(300 * 1000)
test('loads webhook schema data for all versions', async () => {
for (const version in allVersions) {
const webhooks = await getWebhooks(version)
const webhookNames = Object.keys(webhooks)
const versionedWebhooksPage = `/en/${version}/webhooks-and-events/webhooks/webhook-events-and-payloads`
const $ = await getDOM(versionedWebhooksPage)
const domH2Ids = $('h2')
.map((i, h2) => $(h2).attr('id'))
.get()
webhookNames.forEach((webhookName) => {
if (!domH2Ids.includes(webhookName)) {
throw new Error(`Webhook '${webhookName}' not on the ${versionedWebhooksPage} page`)
}
})
}
})
test('Non-GHES versions do not load GHES only webhook', async () => {
// available since 3.4, only in GHES (technically also GHAE which is based
// off of GHES)
const ghesOnlyWebhook = 'cache_sync'
for (const version in allVersions) {
if (!version.includes('enterprise-server') && !version.includes('github-ae')) {
const $ = await getDOM(
`/en/${version}/webhooks-and-events/webhooks/webhook-events-and-payloads`
)
const domH2Ids = $('h2')
.map((i, h2) => $(h2).attr('id'))
.get()
expect(domH2Ids.length).toBeGreaterThan(0)
expect(domH2Ids.includes(ghesOnlyWebhook)).toBe(false)
}
}
})
test('Webhooks events and payloads page has DOM markers needed for extracting search content', async () => {
const $ = await getDOM('/en/webhooks-and-events/webhooks/webhook-events-and-payloads')
const rootSelector = '[data-search=article-body]'
const $root = $(rootSelector)
expect($root.length).toBe(1)
// on the webhooks page the lead is separate from the article body (unlike
// the REST pages for example)
const leadSelector = '[data-search=lead] p'
const $lead = $(leadSelector)
expect($lead.length).toBe(1)
})
// All webhook types don't yet have examples in the schema.
describe.skip('rendering', () => {
test('every webhook event has at least one payload example', async () => {
const versions = Object.values(allVersions).map((value) => value.version)
// For all versions, check that the webhook events and payloads page
// has at least one payload example for each event. Payload examples
// start with the id `webhook-payload-example` and have a sibling div
// with the class `height-constrained-code-block`. The sibling is
// usually but not always the next sibling element, which is why
// `nextUntil` is used.
for (const version of versions) {
const page = `/${version}/webhooks-and-events/webhooks/webhook-events-and-payloads`
const $ = await getDOM(page)
const payloadExampleElem = $('[id^=webhook-payload-example]')
payloadExampleElem.each((i, elem) => {
const siblings = $(elem)
.nextUntil('[id^=webhook-payload-example]')
.filter((i, elem) => $(elem).hasClass('height-constrained-code-block'))
expect(siblings.length).toBeGreaterThan(0)
})
}
})
})
describe('headings', () => {
test('webhook pages do not render any headings with duplicate text', async () => {
const $ = await getDOM('/en/webhooks-and-events/webhooks/webhook-events-and-payloads')
const headingText = $('body')
.find('h2, h3, h4, h5, h6')
.map((i, el) => $(el).text())
.get()
.sort()
const dupes = headingText.filter((item, index) => headingText.indexOf(item) !== index)
const message = `The following duplicate heading texts were found: ${dupes.join(', ')}`
expect(dupes.length, message).toBe(0)
})
test('webhook pages do not render any headings with duplicate ids', async () => {
const $ = await getDOM('/en/webhooks-and-events/webhooks/webhook-events-and-payloads')
const headingIDs = $('body')
.find('h2, h3, h4, h5, h6')
.map((i, el) => $(el).attr('id'))
.get()
.sort()
const dupes = headingIDs.filter((item, index) => headingIDs.indexOf(item) !== index)
const message = `The following duplicate heading IDs were found: ${dupes.join(', ')}`
expect(dupes.length, message).toBe(0)
})
})
})