@@ -2,14 +2,12 @@ import { fileURLToPath } from 'url'
22import path from 'path'
33import { isPlainObject } from 'lodash-es'
44import supertest from 'supertest'
5- import { jest } from '@jest/globals'
6-
75import createApp from '../../lib/app.js'
86import enterpriseServerReleases from '../../lib/enterprise-server-releases.js'
97import Page from '../../lib/page.js'
108import { get } from '../helpers/supertest.js'
119import versionSatisfiesRange from '../../lib/version-satisfies-range.js'
12- import { PREFERRED_LOCALE_COOKIE_NAME } from '../../middleware/detect-language.js '
10+ import { jest } from '@jest/globals '
1311
1412const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
1513
@@ -134,28 +132,6 @@ describe('redirects', () => {
134132 expect ( res . headers . location ) . toBe ( '/ja' )
135133 expect ( res . headers [ 'cache-control' ] ) . toBe ( 'private, no-store' )
136134 } )
137- test ( 'homepage redirects to preferred language by cookie' , async ( ) => {
138- const res = await get ( '/' , {
139- headers : {
140- Cookie : `${ PREFERRED_LOCALE_COOKIE_NAME } =ja` ,
141- 'Accept-Language' : 'es' , // note how this is going to be ignored
142- } ,
143- } )
144- expect ( res . statusCode ) . toBe ( 302 )
145- expect ( res . headers . location ) . toBe ( '/ja' )
146- expect ( res . headers [ 'cache-control' ] ) . toBe ( 'private, no-store' )
147- } )
148- test ( 'homepage redirects to preferred language by cookie if valid' , async ( ) => {
149- const res = await get ( '/' , {
150- headers : {
151- Cookie : `${ PREFERRED_LOCALE_COOKIE_NAME } =xy` ,
152- 'Accept-Language' : 'ja' , // note how this is going to be ignored
153- } ,
154- } )
155- expect ( res . statusCode ) . toBe ( 302 )
156- expect ( res . headers . location ) . toBe ( '/ja' )
157- expect ( res . headers [ 'cache-control' ] ) . toBe ( 'private, no-store' )
158- } )
159135 } )
160136
161137 describe ( 'external redirects' , ( ) => {
@@ -173,63 +149,13 @@ describe('redirects', () => {
173149 } )
174150
175151 describe ( 'localized redirects' , ( ) => {
176- const redirectFrom =
177- '/desktop/contributing-to-projects/changing-a-remote-s-url-from-github-desktop'
178- const redirectTo =
179- '/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/changing-a-remotes-url-from-github-desktop'
180-
181152 test ( 'redirect_from for renamed pages' , async ( ) => {
182- const { res } = await get ( `/ja${ redirectFrom } ` )
153+ const { res } = await get (
154+ '/ja/desktop/contributing-to-projects/changing-a-remote-s-url-from-github-desktop'
155+ )
183156 expect ( res . statusCode ) . toBe ( 301 )
184- const expected = `/ja${ redirectTo } `
185- expect ( res . headers . location ) . toBe ( expected )
186- } )
187-
188- test ( 'redirect_from for renamed pages by Accept-Language header' , async ( ) => {
189- const { res } = await get ( redirectFrom , {
190- headers : {
191- 'Accept-Language' : 'ja' ,
192- } ,
193- } )
194- expect ( res . statusCode ) . toBe ( 302 )
195- const expected = `/ja${ redirectTo } `
196- expect ( res . headers . location ) . toBe ( expected )
197- } )
198-
199- test ( 'redirect_from for renamed pages but ignore Accept-Language header if not recognized' , async ( ) => {
200- const { res } = await get ( redirectFrom , {
201- headers : {
202- // None of these are recognized
203- 'Accept-Language' : 'sv,fr,gr' ,
204- } ,
205- } )
206- expect ( res . statusCode ) . toBe ( 302 )
207- const expected = `/en${ redirectTo } `
208- expect ( res . headers . location ) . toBe ( expected )
209- } )
210-
211- test ( 'redirect_from for renamed pages but ignore unrecognized Accept-Language header values' , async ( ) => {
212- const { res } = await get ( redirectFrom , {
213- headers : {
214- // Only the last one is recognized
215- 'Accept-Language' : 'sv,ja' ,
216- } ,
217- } )
218- expect ( res . statusCode ) . toBe ( 302 )
219- const expected = `/ja${ redirectTo } `
220- expect ( res . headers . location ) . toBe ( expected )
221- } )
222-
223- test ( 'will inject the preferred language from cookie' , async ( ) => {
224- const { res } = await get ( redirectFrom , {
225- headers : {
226- Cookie : `${ PREFERRED_LOCALE_COOKIE_NAME } =ja` ,
227- 'Accept-Language' : 'es' , // note how this is going to be ignored
228- } ,
229- } )
230- // 302 because the redirect depended on cookie
231- expect ( res . statusCode ) . toBe ( 302 )
232- const expected = `/ja${ redirectTo } `
157+ const expected =
158+ '/ja/desktop/contributing-and-collaborating-using-github-desktop/working-with-your-remote-repository-on-github-or-github-enterprise/changing-a-remotes-url-from-github-desktop'
233159 expect ( res . headers . location ) . toBe ( expected )
234160 } )
235161 } )
0 commit comments