-
Notifications
You must be signed in to change notification settings - Fork 66.8k
Expand file tree
/
Copy pathpagelist.ts
More file actions
81 lines (69 loc) · 2.91 KB
/
pagelist.ts
File metadata and controls
81 lines (69 loc) · 2.91 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
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
import { beforeAll, describe, expect, test } from 'vitest'
import { get } from '@/tests/helpers/e2etest'
import { allVersionKeys } from '@/versions/lib/all-versions'
import nonEnterpriseDefaultVersion from '@/versions/lib/non-enterprise-default-version'
describe.each(allVersionKeys)('pagelist api for %s', async (versionKey) => {
beforeAll(() => {
// If you didn't set the `ROOT` variable, the tests will fail rather
// cryptically. So as a warning for engineers running these tests,
// alert in case it was accidentally forgotten.
if (!process.env.ROOT) {
console.warn(
'WARNING: The pagelist tests require the ROOT environment variable to be set to the fixture root',
)
}
// Ditto for fixture-based translations to work
if (!process.env.TRANSLATIONS_FIXTURE_ROOT) {
console.warn(
'WARNING: The pagelist tests require the TRANSLATIONS_FIXTURE_ROOT environment variable to be set',
)
}
})
// queries the pagelist API for each version
const res = await get(`/api/pagelist/en/${versionKey}`)
test('is reachable, returns 200 OK', async () => {
expect(res.statusCode).toBe(200)
})
// there's a large assortment of possible URLs,
// even "/en" is an acceptable URL, so regexes capture lots
test('contains valid urls matching the requested version', async () => {
let expression
// if we're testing the default version, it may be missing
// from the url altogether so we need a slightly different regex
if (versionKey === nonEnterpriseDefaultVersion)
expression = new RegExp(`/\\w{2}(/${versionKey})?/?.*`)
else expression = new RegExp(`/\\w{2}/${versionKey}/?.*`)
res.body
.trim()
.split('\n')
.forEach((permalink: string) => {
expect(permalink).toMatch(expression)
})
})
test('English requests only returns urls that contain /en', async () => {
const expression = new RegExp(`^/en(/${nonEnterpriseDefaultVersion})?/?.*`)
res.body
.trim()
.split('\n')
.forEach((permalink: string) => {
expect(permalink).toMatch(expression)
})
})
})
describe('Redirect Tests', () => {
test('redirects without version suffix', async () => {
const res = await get(`/api/pagelist`)
expect(res.statusCode).toBe(308)
expect(res.headers.location).toBe(`/api/pagelist/en/${nonEnterpriseDefaultVersion}`)
})
test('should redirect to /pagelist/en/:product@:version when URL does not include /en', async () => {
const res = await get('/api/pagelist/free-pro-team@latest')
expect(res.statusCode).toBe(308)
expect(res.headers.location).toBe('/api/pagelist/en/free-pro-team@latest')
})
test('should redirect to /pagelist/en/free-pro-team@lateset when URL does not include version', async () => {
const res = await get('/api/pagelist/en')
expect(res.statusCode).toBe(308)
expect(res.headers.location).toBe('/api/pagelist/en/free-pro-team@latest')
})
})