1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/tests/rendering/early-access-paths.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

65 lines
1.7 KiB
JavaScript

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()
})
})