forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredirects.js
More file actions
47 lines (43 loc) · 1.69 KB
/
redirects.js
File metadata and controls
47 lines (43 loc) · 1.69 KB
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
import { languageKeys } from '#src/languages/lib/languages.js'
import { get } from '../../../tests/helpers/e2etest.js'
import { USER_LANGUAGE_COOKIE_NAME } from '../../../lib/constants.js'
const langs = languageKeys.filter((lang) => lang !== 'en')
describe('redirects', () => {
test.each(langs)('redirects to %s if accept-language', async (lang) => {
const acceptLanguage = lang === 'zh' ? 'zh-CN' : lang
const res = await get('/get-started', {
headers: { 'accept-language': acceptLanguage },
followRedirects: false,
})
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe(`/${lang}/get-started`)
expect(res.headers['cache-control']).toContain('public')
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
expect(res.headers['set-cookie']).toBeUndefined()
})
test.each(langs)('redirects to %s if USER_LANGUAGE_COOKIE_NAME', async (lang) => {
const res = await get('/get-started', {
headers: {
'accept-language': 'en',
Cookie: `${USER_LANGUAGE_COOKIE_NAME}=${lang}`,
},
followRedirects: false,
})
expect(res.statusCode).toBe(302)
expect(res.headers.location).toBe(`/${lang}/get-started`)
expect(res.headers['cache-control']).toContain('public')
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
expect(res.headers['set-cookie']).toBeUndefined()
})
test.each([
['/jp', '/ja'],
['/zh-CN', '/zh'],
['/br', '/pt'],
['/kr', '/ko'],
])('redirects %s to %s', async (from, to_) => {
const res = await get(from)
expect(res.statusCode).toBe(301)
expect(res.headers['cache-control']).toMatch(/max-age=\d+/)
expect(res.headers.location).toBe(to_)
})
})