@@ -4,7 +4,18 @@ import { get } from '#src/tests/helpers/e2etest.js'
4
4
import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
5
5
import { latest } from '#src/versions/lib/enterprise-server-releases.js'
6
6
7
- const makeURL = ( pathname ) => `/api/article/meta?${ new URLSearchParams ( { pathname } ) } `
7
+ const makeURL = ( pathname : string ) : string =>
8
+ `/api/article/meta?${ new URLSearchParams ( { pathname } ) } `
9
+
10
+ interface PageMetadata {
11
+ product : string
12
+ title : string
13
+ intro : string
14
+ }
15
+
16
+ interface ErrorResponse {
17
+ error : string
18
+ }
8
19
9
20
describe ( 'pageinfo api' , ( ) => {
10
21
beforeAll ( ( ) => {
@@ -27,7 +38,7 @@ describe('pageinfo api', () => {
27
38
test ( 'happy path' , async ( ) => {
28
39
const res = await get ( makeURL ( '/en/get-started/start-your-journey' ) )
29
40
expect ( res . statusCode ) . toBe ( 200 )
30
- const meta = JSON . parse ( res . body )
41
+ const meta = JSON . parse ( res . body ) as PageMetadata
31
42
expect ( meta . product ) . toBe ( 'Get started' )
32
43
expect ( meta . title ) . toBe ( 'Start your journey' )
33
44
expect ( meta . intro ) . toBe (
@@ -45,28 +56,28 @@ describe('pageinfo api', () => {
45
56
test ( 'a pathname that does not exist' , async ( ) => {
46
57
const res = await get ( makeURL ( '/en/never/heard/of' ) )
47
58
expect ( res . statusCode ) . toBe ( 404 )
48
- const { error } = JSON . parse ( res . body )
59
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
49
60
expect ( error ) . toBe ( "No page found for '/en/never/heard/of'" )
50
61
} )
51
62
52
63
test ( "no 'pathname' query string at all" , async ( ) => {
53
64
const res = await get ( '/api/article/meta' )
54
65
expect ( res . statusCode ) . toBe ( 400 )
55
- const { error } = JSON . parse ( res . body )
66
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
56
67
expect ( error ) . toBe ( "No 'pathname' query" )
57
68
} )
58
69
59
70
test ( "empty 'pathname' query string" , async ( ) => {
60
71
const res = await get ( '/api/article/meta?pathname=%20' )
61
72
expect ( res . statusCode ) . toBe ( 400 )
62
- const { error } = JSON . parse ( res . body )
73
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
63
74
expect ( error ) . toBe ( "'pathname' query empty" )
64
75
} )
65
76
66
77
test ( 'repeated pathname query string key' , async ( ) => {
67
78
const res = await get ( '/api/article/meta?pathname=a&pathname=b' )
68
79
expect ( res . statusCode ) . toBe ( 400 )
69
- const { error } = JSON . parse ( res . body )
80
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
70
81
expect ( error ) . toBe ( "Multiple 'pathname' keys" )
71
82
} )
72
83
@@ -75,28 +86,28 @@ describe('pageinfo api', () => {
75
86
{
76
87
const res = await get ( makeURL ( '/en/olden-days' ) )
77
88
expect ( res . statusCode ) . toBe ( 200 )
78
- const meta = JSON . parse ( res . body )
89
+ const meta = JSON . parse ( res . body ) as PageMetadata
79
90
expect ( meta . title ) . toBe ( 'HubGit.com Fixture Documentation' )
80
91
}
81
92
// Trailing slashes are always removed
82
93
{
83
94
const res = await get ( makeURL ( '/en/olden-days/' ) )
84
95
expect ( res . statusCode ) . toBe ( 200 )
85
- const meta = JSON . parse ( res . body )
96
+ const meta = JSON . parse ( res . body ) as PageMetadata
86
97
expect ( meta . title ) . toBe ( 'HubGit.com Fixture Documentation' )
87
98
}
88
99
// Short code for latest version
89
100
{
90
101
const res = await get ( makeURL ( '/en/enterprise-server@latest/get-started/liquid/ifversion' ) )
91
102
expect ( res . statusCode ) . toBe ( 200 )
92
- const meta = JSON . parse ( res . body )
103
+ const meta = JSON . parse ( res . body ) as PageMetadata
93
104
expect ( meta . intro ) . toMatch ( / \( n o t o n f p t \) / )
94
105
}
95
106
// A URL that doesn't have fpt as an available version
96
107
{
97
108
const res = await get ( makeURL ( '/en/get-started/versioning/only-ghec-and-ghes' ) )
98
109
expect ( res . statusCode ) . toBe ( 200 )
99
- const meta = JSON . parse ( res . body )
110
+ const meta = JSON . parse ( res . body ) as PageMetadata
100
111
expect ( meta . title ) . toBe ( 'Only in Enterprise Cloud and Enterprise Server' )
101
112
}
102
113
} )
@@ -108,14 +119,14 @@ describe('pageinfo api', () => {
108
119
{
109
120
const res = await get ( makeURL ( '/en/get-started/liquid/ifversion' ) )
110
121
expect ( res . statusCode ) . toBe ( 200 )
111
- const meta = JSON . parse ( res . body )
122
+ const meta = JSON . parse ( res . body ) as PageMetadata
112
123
expect ( meta . intro ) . toMatch ( / \( o n f p t \) / )
113
124
}
114
125
// Second on any other version
115
126
{
116
127
const res = await get ( makeURL ( '/en/enterprise-server@latest/get-started/liquid/ifversion' ) )
117
128
expect ( res . statusCode ) . toBe ( 200 )
118
- const meta = JSON . parse ( res . body )
129
+ const meta = JSON . parse ( res . body ) as PageMetadata
119
130
expect ( meta . intro ) . toMatch ( / \( n o t o n f p t \) / )
120
131
}
121
132
} )
@@ -125,7 +136,7 @@ describe('pageinfo api', () => {
125
136
{
126
137
const res = await get ( makeURL ( '/en' ) )
127
138
expect ( res . statusCode ) . toBe ( 200 )
128
- const meta = JSON . parse ( res . body )
139
+ const meta = JSON . parse ( res . body ) as PageMetadata
129
140
expect ( meta . title ) . toMatch ( 'HubGit.com Fixture Documentation' )
130
141
}
131
142
// enterprise-server with language specified
@@ -137,7 +148,7 @@ describe('pageinfo api', () => {
137
148
{
138
149
const res = await get ( makeURL ( `/en/enterprise-server@${ latest } ` ) )
139
150
expect ( res . statusCode ) . toBe ( 200 )
140
- const meta = JSON . parse ( res . body )
151
+ const meta = JSON . parse ( res . body ) as PageMetadata
141
152
expect ( meta . title ) . toMatch ( 'HubGit Enterprise Server Fixture Documentation' )
142
153
}
143
154
} )
@@ -147,14 +158,14 @@ describe('pageinfo api', () => {
147
158
{
148
159
const res = await get ( makeURL ( '/' ) )
149
160
expect ( res . statusCode ) . toBe ( 200 )
150
- const meta = JSON . parse ( res . body )
161
+ const meta = JSON . parse ( res . body ) as PageMetadata
151
162
expect ( meta . title ) . toMatch ( 'HubGit.com Fixture Documentation' )
152
163
}
153
164
// enterprise-server without language specified
154
165
{
155
166
const res = await get ( makeURL ( '/enterprise-server@latest' ) )
156
167
expect ( res . statusCode ) . toBe ( 200 )
157
- const meta = JSON . parse ( res . body )
168
+ const meta = JSON . parse ( res . body ) as PageMetadata
158
169
expect ( meta . title ) . toMatch ( 'HubGit Enterprise Server Fixture Documentation' )
159
170
}
160
171
} )
@@ -169,38 +180,38 @@ describe('pageinfo api', () => {
169
180
{
170
181
const res = await get ( makeURL ( '/en/enterprise-server@3.2' ) )
171
182
expect ( res . statusCode ) . toBe ( 200 )
172
- const meta = JSON . parse ( res . body )
183
+ const meta = JSON . parse ( res . body ) as PageMetadata
173
184
expect ( meta . title ) . toMatch ( 'GitHub Enterprise Server 3.2 Help Documentation' )
174
185
}
175
186
176
187
// The oldest known archived version that we proxy
177
188
{
178
189
const res = await get ( makeURL ( '/en/enterprise/11.10.340' ) )
179
190
expect ( res . statusCode ) . toBe ( 200 )
180
- const meta = JSON . parse ( res . body )
191
+ const meta = JSON . parse ( res . body ) as PageMetadata
181
192
expect ( meta . title ) . toMatch ( 'GitHub Enterprise Server 11.10.340 Help Documentation' )
182
193
}
183
194
} )
184
195
185
196
test ( 'pathname has to start with /' , async ( ) => {
186
197
const res = await get ( makeURL ( 'ip' ) )
187
198
expect ( res . statusCode ) . toBe ( 400 )
188
- const { error } = JSON . parse ( res . body )
199
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
189
200
expect ( error ) . toBe ( "'pathname' has to start with /" )
190
201
} )
191
202
192
203
test ( "pathname can't contain spaces /" , async ( ) => {
193
204
const res = await get ( makeURL ( '/en foo bar' ) )
194
205
expect ( res . statusCode ) . toBe ( 400 )
195
- const { error } = JSON . parse ( res . body )
206
+ const { error } = JSON . parse ( res . body ) as ErrorResponse
196
207
expect ( error ) . toBe ( "'pathname' cannot contain whitespace" )
197
208
} )
198
209
199
210
describe ( 'translations' , ( ) => {
200
211
test ( 'Japanese page' , async ( ) => {
201
212
const res = await get ( makeURL ( '/ja/get-started/start-your-journey/hello-world' ) )
202
213
expect ( res . statusCode ) . toBe ( 200 )
203
- const meta = JSON . parse ( res . body )
214
+ const meta = JSON . parse ( res . body ) as PageMetadata
204
215
expect ( meta . product ) . toBe ( 'はじめに' )
205
216
expect ( meta . title ) . toBe ( 'こんにちは World' )
206
217
expect ( meta . intro ) . toBe ( 'この Hello World 演習に従って、HubGit の使用を開始します。' )
@@ -213,8 +224,8 @@ describe('pageinfo api', () => {
213
224
// even exist on disk. So it'll fall back to English.
214
225
const translationRes = await get ( makeURL ( '/ja/get-started/start-your-journey' ) )
215
226
expect ( translationRes . statusCode ) . toBe ( 200 )
216
- const en = JSON . parse ( enRes . body )
217
- const translation = JSON . parse ( translationRes . body )
227
+ const en = JSON . parse ( enRes . body ) as PageMetadata
228
+ const translation = JSON . parse ( translationRes . body ) as PageMetadata
218
229
expect ( en . title ) . toBe ( translation . title )
219
230
expect ( en . intro ) . toBe ( translation . intro )
220
231
} )
0 commit comments