forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathearly-access-paths.js
64 lines (57 loc) · 1.65 KB
/
early-access-paths.js
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
const MockExpressResponse = require('mock-express-response')
const middleware = require('../../middleware/early-access-paths')
describe('GET /early-access-paths.json', () => {
beforeEach(() => {
delete process.env['early-access-shared-secret']
})
test('responds with 401 if shared secret is missing', async () => {
const req = {
path: '/early-access-paths.json',
headers: {}
}
const res = new MockExpressResponse()
const next = jest.fn()
await middleware(req, res, next)
expect(res._getJSON()).toEqual({ error: '401 Unauthorized' })
})
test('responds with an array of hidden paths', async () => {
process.env.EARLY_ACCESS_SHARED_SECRET = 'bananas'
const req = {
path: '/early-access-paths.json',
headers: {
'early-access-shared-secret': 'bananas'
},
context: {
pages: [
{
hidden: true,
languageCode: 'en',
permalinks: [
{ href: '/some-hidden-page' }
],
redirects: {
'/old-hidden-page': '/new-hidden-page'
}
},
{
hidden: false,
languageCode: 'en'
}
]
}
}
const res = new MockExpressResponse()
const next = jest.fn()
await middleware(req, res, next)
expect(res._getJSON()).toEqual(['/some-hidden-page', '/old-hidden-page'])
})
test('ignores requests to other paths', async () => {
const req = {
path: '/not-early-access'
}
const res = new MockExpressResponse()
const next = jest.fn()
await middleware(req, res, next)
expect(next).toHaveBeenCalled()
})
})