@@ -4,7 +4,18 @@ import { get } from '#src/tests/helpers/e2etest.js'
44import { SURROGATE_ENUMS } from '#src/frame/middleware/set-fastly-surrogate-key.js'
55import { latest } from '#src/versions/lib/enterprise-server-releases.js'
66
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+ }
819
920describe ( 'pageinfo api' , ( ) => {
1021 beforeAll ( ( ) => {
@@ -27,7 +38,7 @@ describe('pageinfo api', () => {
2738 test ( 'happy path' , async ( ) => {
2839 const res = await get ( makeURL ( '/en/get-started/start-your-journey' ) )
2940 expect ( res . statusCode ) . toBe ( 200 )
30- const meta = JSON . parse ( res . body )
41+ const meta = JSON . parse ( res . body ) as PageMetadata
3142 expect ( meta . product ) . toBe ( 'Get started' )
3243 expect ( meta . title ) . toBe ( 'Start your journey' )
3344 expect ( meta . intro ) . toBe (
@@ -45,28 +56,28 @@ describe('pageinfo api', () => {
4556 test ( 'a pathname that does not exist' , async ( ) => {
4657 const res = await get ( makeURL ( '/en/never/heard/of' ) )
4758 expect ( res . statusCode ) . toBe ( 404 )
48- const { error } = JSON . parse ( res . body )
59+ const { error } = JSON . parse ( res . body ) as ErrorResponse
4960 expect ( error ) . toBe ( "No page found for '/en/never/heard/of'" )
5061 } )
5162
5263 test ( "no 'pathname' query string at all" , async ( ) => {
5364 const res = await get ( '/api/article/meta' )
5465 expect ( res . statusCode ) . toBe ( 400 )
55- const { error } = JSON . parse ( res . body )
66+ const { error } = JSON . parse ( res . body ) as ErrorResponse
5667 expect ( error ) . toBe ( "No 'pathname' query" )
5768 } )
5869
5970 test ( "empty 'pathname' query string" , async ( ) => {
6071 const res = await get ( '/api/article/meta?pathname=%20' )
6172 expect ( res . statusCode ) . toBe ( 400 )
62- const { error } = JSON . parse ( res . body )
73+ const { error } = JSON . parse ( res . body ) as ErrorResponse
6374 expect ( error ) . toBe ( "'pathname' query empty" )
6475 } )
6576
6677 test ( 'repeated pathname query string key' , async ( ) => {
6778 const res = await get ( '/api/article/meta?pathname=a&pathname=b' )
6879 expect ( res . statusCode ) . toBe ( 400 )
69- const { error } = JSON . parse ( res . body )
80+ const { error } = JSON . parse ( res . body ) as ErrorResponse
7081 expect ( error ) . toBe ( "Multiple 'pathname' keys" )
7182 } )
7283
@@ -75,28 +86,28 @@ describe('pageinfo api', () => {
7586 {
7687 const res = await get ( makeURL ( '/en/olden-days' ) )
7788 expect ( res . statusCode ) . toBe ( 200 )
78- const meta = JSON . parse ( res . body )
89+ const meta = JSON . parse ( res . body ) as PageMetadata
7990 expect ( meta . title ) . toBe ( 'HubGit.com Fixture Documentation' )
8091 }
8192 // Trailing slashes are always removed
8293 {
8394 const res = await get ( makeURL ( '/en/olden-days/' ) )
8495 expect ( res . statusCode ) . toBe ( 200 )
85- const meta = JSON . parse ( res . body )
96+ const meta = JSON . parse ( res . body ) as PageMetadata
8697 expect ( meta . title ) . toBe ( 'HubGit.com Fixture Documentation' )
8798 }
8899 // Short code for latest version
89100 {
90101 const res = await get ( makeURL ( '/en/enterprise-server@latest/get-started/liquid/ifversion' ) )
91102 expect ( res . statusCode ) . toBe ( 200 )
92- const meta = JSON . parse ( res . body )
103+ const meta = JSON . parse ( res . body ) as PageMetadata
93104 expect ( meta . intro ) . toMatch ( / \( n o t o n f p t \) / )
94105 }
95106 // A URL that doesn't have fpt as an available version
96107 {
97108 const res = await get ( makeURL ( '/en/get-started/versioning/only-ghec-and-ghes' ) )
98109 expect ( res . statusCode ) . toBe ( 200 )
99- const meta = JSON . parse ( res . body )
110+ const meta = JSON . parse ( res . body ) as PageMetadata
100111 expect ( meta . title ) . toBe ( 'Only in Enterprise Cloud and Enterprise Server' )
101112 }
102113 } )
@@ -108,14 +119,14 @@ describe('pageinfo api', () => {
108119 {
109120 const res = await get ( makeURL ( '/en/get-started/liquid/ifversion' ) )
110121 expect ( res . statusCode ) . toBe ( 200 )
111- const meta = JSON . parse ( res . body )
122+ const meta = JSON . parse ( res . body ) as PageMetadata
112123 expect ( meta . intro ) . toMatch ( / \( o n f p t \) / )
113124 }
114125 // Second on any other version
115126 {
116127 const res = await get ( makeURL ( '/en/enterprise-server@latest/get-started/liquid/ifversion' ) )
117128 expect ( res . statusCode ) . toBe ( 200 )
118- const meta = JSON . parse ( res . body )
129+ const meta = JSON . parse ( res . body ) as PageMetadata
119130 expect ( meta . intro ) . toMatch ( / \( n o t o n f p t \) / )
120131 }
121132 } )
@@ -125,7 +136,7 @@ describe('pageinfo api', () => {
125136 {
126137 const res = await get ( makeURL ( '/en' ) )
127138 expect ( res . statusCode ) . toBe ( 200 )
128- const meta = JSON . parse ( res . body )
139+ const meta = JSON . parse ( res . body ) as PageMetadata
129140 expect ( meta . title ) . toMatch ( 'HubGit.com Fixture Documentation' )
130141 }
131142 // enterprise-server with language specified
@@ -137,7 +148,7 @@ describe('pageinfo api', () => {
137148 {
138149 const res = await get ( makeURL ( `/en/enterprise-server@${ latest } ` ) )
139150 expect ( res . statusCode ) . toBe ( 200 )
140- const meta = JSON . parse ( res . body )
151+ const meta = JSON . parse ( res . body ) as PageMetadata
141152 expect ( meta . title ) . toMatch ( 'HubGit Enterprise Server Fixture Documentation' )
142153 }
143154 } )
@@ -147,14 +158,14 @@ describe('pageinfo api', () => {
147158 {
148159 const res = await get ( makeURL ( '/' ) )
149160 expect ( res . statusCode ) . toBe ( 200 )
150- const meta = JSON . parse ( res . body )
161+ const meta = JSON . parse ( res . body ) as PageMetadata
151162 expect ( meta . title ) . toMatch ( 'HubGit.com Fixture Documentation' )
152163 }
153164 // enterprise-server without language specified
154165 {
155166 const res = await get ( makeURL ( '/enterprise-server@latest' ) )
156167 expect ( res . statusCode ) . toBe ( 200 )
157- const meta = JSON . parse ( res . body )
168+ const meta = JSON . parse ( res . body ) as PageMetadata
158169 expect ( meta . title ) . toMatch ( 'HubGit Enterprise Server Fixture Documentation' )
159170 }
160171 } )
@@ -169,38 +180,38 @@ describe('pageinfo api', () => {
169180 {
170181 const res = await get ( makeURL ( '/en/[email protected] ' ) ) 171182 expect ( res . statusCode ) . toBe ( 200 )
172- const meta = JSON . parse ( res . body )
183+ const meta = JSON . parse ( res . body ) as PageMetadata
173184 expect ( meta . title ) . toMatch ( 'GitHub Enterprise Server 3.2 Help Documentation' )
174185 }
175186
176187 // The oldest known archived version that we proxy
177188 {
178189 const res = await get ( makeURL ( '/en/enterprise/11.10.340' ) )
179190 expect ( res . statusCode ) . toBe ( 200 )
180- const meta = JSON . parse ( res . body )
191+ const meta = JSON . parse ( res . body ) as PageMetadata
181192 expect ( meta . title ) . toMatch ( 'GitHub Enterprise Server 11.10.340 Help Documentation' )
182193 }
183194 } )
184195
185196 test ( 'pathname has to start with /' , async ( ) => {
186197 const res = await get ( makeURL ( 'ip' ) )
187198 expect ( res . statusCode ) . toBe ( 400 )
188- const { error } = JSON . parse ( res . body )
199+ const { error } = JSON . parse ( res . body ) as ErrorResponse
189200 expect ( error ) . toBe ( "'pathname' has to start with /" )
190201 } )
191202
192203 test ( "pathname can't contain spaces /" , async ( ) => {
193204 const res = await get ( makeURL ( '/en foo bar' ) )
194205 expect ( res . statusCode ) . toBe ( 400 )
195- const { error } = JSON . parse ( res . body )
206+ const { error } = JSON . parse ( res . body ) as ErrorResponse
196207 expect ( error ) . toBe ( "'pathname' cannot contain whitespace" )
197208 } )
198209
199210 describe ( 'translations' , ( ) => {
200211 test ( 'Japanese page' , async ( ) => {
201212 const res = await get ( makeURL ( '/ja/get-started/start-your-journey/hello-world' ) )
202213 expect ( res . statusCode ) . toBe ( 200 )
203- const meta = JSON . parse ( res . body )
214+ const meta = JSON . parse ( res . body ) as PageMetadata
204215 expect ( meta . product ) . toBe ( 'はじめに' )
205216 expect ( meta . title ) . toBe ( 'こんにちは World' )
206217 expect ( meta . intro ) . toBe ( 'この Hello World 演習に従って、HubGit の使用を開始します。' )
@@ -213,8 +224,8 @@ describe('pageinfo api', () => {
213224 // even exist on disk. So it'll fall back to English.
214225 const translationRes = await get ( makeURL ( '/ja/get-started/start-your-journey' ) )
215226 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
218229 expect ( en . title ) . toBe ( translation . title )
219230 expect ( en . intro ) . toBe ( translation . intro )
220231 } )
0 commit comments