Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

rest.js 2.7 KB

You have to be logged in to leave a comment. Sign In
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
  1. const fs = require('fs').promises
  2. const path = require('path')
  3. const { difference, isPlainObject } = require('lodash')
  4. const { getJSON } = require('../helpers/supertest')
  5. const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
  6. // list of REST markdown files that do not correspond to REST API resources
  7. // TODO could we get this list dynamically, say via page frontmatter?
  8. const excludeFromResourceNameCheck = [
  9. 'endpoints-available-for-github-apps.md',
  10. 'permissions-required-for-github-apps.md',
  11. 'index.md'
  12. ]
  13. describe('REST references docs', () => {
  14. jest.setTimeout(3 * 60 * 1000)
  15. test('markdown file exists for every operationId prefix in the api.github.com schema', async () => {
  16. const { categories } = require('../../lib/rest')
  17. const referenceDir = path.join(__dirname, '../../content/rest/reference')
  18. const filenames = (await fs.readdir(referenceDir))
  19. .filter(filename => !excludeFromResourceNameCheck.find(excludedFile => filename.endsWith(excludedFile)))
  20. .map(filename => filename.replace('.md', ''))
  21. const missingResource = 'Found a markdown file in content/rest/reference that is not represented by an OpenAPI REST operation category.'
  22. expect(difference(filenames, categories), missingResource).toEqual([])
  23. const missingFile = 'Found an OpenAPI REST operation category that is not represented by a markdown file in content/rest/reference.'
  24. expect(difference(categories, filenames), missingFile).toEqual([])
  25. })
  26. test('loads api.github.com OpenAPI schema data', async () => {
  27. const operations = await getJSON('/en/rest/reference/emojis?json=currentRestOperations')
  28. expect(JSON.stringify(operations).includes('GitHub Enterprise')).toBe(false)
  29. })
  30. test('loads Enterprise OpenAPI schema data', async () => {
  31. const operations = await getJSON(`/en/enterprise/${enterpriseServerReleases.oldestSupported}/user/rest/reference/emojis?json=currentRestOperations`)
  32. const operation = operations.find(operation => operation.operationId === 'emojis/get')
  33. expect(isPlainObject(operation)).toBe(true)
  34. expect(operation.description).toContain('GitHub Enterprise')
  35. })
  36. test('loads operations enabled for GitHub Apps', async () => {
  37. const operations = await getJSON('/en/free-pro-team@latest/rest/overview/endpoints-available-for-github-apps?json=rest.operationsEnabledForGitHubApps')
  38. expect(operations['free-pro-team@latest'].actions.length).toBeGreaterThan(0)
  39. expect(operations['enterprise-server@2.22'].actions.length).toBeGreaterThan(0)
  40. })
  41. test('no wrongly detected AppleScript syntax highlighting in schema data', async () => {
  42. const { operations } = require('../../lib/rest')
  43. expect(JSON.stringify(operations).includes('hljs language-applescript')).toBe(false)
  44. })
  45. })
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...