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

developer-site-redirects.js 6.2 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
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
143
144
  1. const path = require('path')
  2. const { eachOfLimit } = require('async')
  3. const enterpriseServerReleases = require('../../lib/enterprise-server-releases')
  4. const { get } = require('../helpers/supertest')
  5. const restRedirectFixtures = require('../fixtures/rest-redirects')
  6. const graphqlRedirectFixtures = require('../fixtures/graphql-redirects')
  7. const developerRedirectFixtures = require('../fixtures/developer-redirects')
  8. const MAX_CONCURRENT_REQUESTS = 50
  9. describe('developer redirects', () => {
  10. jest.setTimeout(60 * 1000)
  11. beforeAll(async () => {
  12. // The first page load takes a long time so let's get it out of the way in
  13. // advance to call out that problem specifically rather than misleadingly
  14. // attributing it to the first test
  15. await get('/v4')
  16. })
  17. describe('redirects /v4 requests to /graphql', () => {
  18. test('graphql homepage', async () => {
  19. const res = await get('/v4')
  20. expect(res.statusCode).toBe(301)
  21. const expectedFinalPath = '/en/graphql'
  22. expect(res.headers.location).toBe(expectedFinalPath)
  23. })
  24. test('graphql enterprise homepage', async () => {
  25. const res = await get('/enterprise/v4', { followAllRedirects: true })
  26. expect(res.statusCode).toBe(200)
  27. const finalPath = (new URL(res.request.url)).pathname
  28. const expectedFinalPath = `/en/enterprise-server@${enterpriseServerReleases.latest}/graphql`
  29. expect(finalPath).toBe(expectedFinalPath)
  30. })
  31. test('graphql overview paths', async () => {
  32. const oldPath = '/v4/breaking_changes'
  33. const newPath = '/graphql/overview/breaking-changes'
  34. const res = await get(oldPath)
  35. expect(res.statusCode).toBe(301)
  36. expect(res.headers.location).toBe(`/en${newPath}`)
  37. const enterpriseRes = await get(`/enterprise${oldPath}`, { followAllRedirects: true })
  38. expect(enterpriseRes.statusCode).toBe(200)
  39. const finalPath = (new URL(enterpriseRes.request.url)).pathname
  40. const expectedFinalPath = path.join('/', `enterprise-server@${enterpriseServerReleases.latest}`, newPath)
  41. expect(finalPath).toBe(`/en${expectedFinalPath}`)
  42. })
  43. test('graphql reference paths with child pages', async () => {
  44. const sclarRes = await get('/en/v4/scalar/boolean')
  45. expect(sclarRes.statusCode).toBe(301)
  46. const sclarResFinalPath = '/en/graphql/reference/scalars#boolean'
  47. expect(sclarRes.headers.location).toBe(sclarResFinalPath)
  48. const enumRes = await get('/en/v4/enum/searchtype')
  49. expect(enumRes.statusCode).toBe(301)
  50. const enumResFinalPath = '/en/graphql/reference/enums#searchtype'
  51. expect(enumRes.headers.location).toBe(enumResFinalPath)
  52. })
  53. })
  54. test('redirects /v3 requests to /rest', async () => {
  55. let expectedFinalPath
  56. let res = await get('/v3')
  57. expect(res.statusCode).toBe(301)
  58. expectedFinalPath = '/en/rest'
  59. expect(res.headers.location).toBe(expectedFinalPath)
  60. // REST subresources like activity notifications don't have their own page
  61. // any more, so redirect to an anchor on the resource page
  62. res = await get('/en/v3/activity')
  63. expect(res.statusCode).toBe(301)
  64. expectedFinalPath = '/en/rest/reference/activity'
  65. expect(res.headers.location).toBe(expectedFinalPath)
  66. // REST subresources like activity notifications don't have their own page
  67. // any more, so redirect to an anchor on the resource page
  68. res = await get('/en/v3/activity/notifications')
  69. expect(res.statusCode).toBe(301)
  70. expectedFinalPath = '/en/rest/reference/activity#notifications'
  71. expect(res.headers.location).toBe(expectedFinalPath)
  72. // trailing slashes are handled separately by the `slashes` module;
  73. // any request to a /v3 URL with a trailing slash will be redirected twice
  74. res = await get('/en/v3/activity/notifications/')
  75. expect(res.statusCode).toBe(301)
  76. expect(res.headers.location).toBe('/en/v3/activity/notifications')
  77. // non-reference redirects (e.g. guides)
  78. res = await get('/en/v3/guides/basics-of-authentication')
  79. expect(res.statusCode).toBe(301)
  80. expectedFinalPath = '/en/rest/guides/basics-of-authentication'
  81. expect(res.headers.location).toBe(expectedFinalPath)
  82. })
  83. describe('fixtures', () => {
  84. // this fixtures file includes paths like /apps and /webhooks, plus /enterprise paths
  85. test('developer redirects', async () => {
  86. await eachOfLimit(
  87. developerRedirectFixtures,
  88. MAX_CONCURRENT_REQUESTS,
  89. async (newPath, oldPath) => {
  90. const res = await get(oldPath)
  91. expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
  92. expect(res.headers.location).toBe(newPath)
  93. }
  94. )
  95. })
  96. // this fixtures file includes /v3 and /enterprise/v3 paths
  97. test('rest reference redirects', async () => {
  98. await eachOfLimit(
  99. restRedirectFixtures,
  100. MAX_CONCURRENT_REQUESTS,
  101. async (newPath, oldPath) => {
  102. // REST and GraphQL developer Enterprise paths with a version are only supported up to 2.21.
  103. // We make an exception to always redirect versionless paths to the latest version.
  104. newPath = newPath.replace('/enterprise-server/', `/enterprise-server@${enterpriseServerReleases.latest}/`)
  105. const res = await get(oldPath)
  106. expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
  107. expect(res.headers.location, `${oldPath} did not redirect to ${newPath}`).toBe(newPath)
  108. }
  109. )
  110. })
  111. // this fixtures file includes /v4 and /enterprise/v4 paths
  112. test('graphql reference redirects', async () => {
  113. await eachOfLimit(
  114. graphqlRedirectFixtures,
  115. MAX_CONCURRENT_REQUESTS,
  116. async (newPath, oldPath) => {
  117. // REST and GraphQL developer Enterprise paths with a version are only supported up to 2.21.
  118. // We make an exception to always redirect versionless paths to the latest version.
  119. newPath = newPath.replace('/enterprise-server/', `/enterprise-server@${enterpriseServerReleases.latest}/`)
  120. const res = await get(oldPath)
  121. expect(res.statusCode, `${oldPath} did not redirect to ${newPath}`).toBe(301)
  122. expect(res.headers.location, `${oldPath} did not redirect to ${newPath}`).toBe(newPath)
  123. }
  124. )
  125. })
  126. })
  127. })
Tip!

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

Comments

Loading...