* refactor(routes): remove unused sitemap route * style(comments): enforce consistent comment style * style(exports): enforce consistent export style * chore: Add jsDoc for contentful service * chore: Add jsDoc for contentful service \n \n closes #23 * refactor(app): move query parameter comment to right position and mention comment route middleware * test(npm): add temporary test script * refactor(middlewares): split up bootstrap middleware - fixes #23759 * refactor(cookies): use constances to give context the maxAge cookie setting * refactor(variables): use more descriptive names for variables * space became spaceId when it was just the id not the full space instance * all (access) token variable name variants became [api-type]Token * all clients are now called deliveryClient or previewClient * cpa and cda only remain when they are used as actual API id * env variables names adjusted * perf(helpers): only run marked when content is not empty * refactor(comments): fix typos * refactor(comments): add hint why error is logged to console in settings * chore: Add comments to routes and services * refactor(requires): order and group requires * fix(settings): add validation for wrong preview token * chore: Add comments to routes * chore: fix typo * chore: console.error -> throw * chore: move cookie name to a constant * chore: Fix app.js comment * typo: removing t * chore: typos * chore: removed unnecessary comment line sign * chore: newline for readabillity * chore: remove dangling `t` * chore: remove `t`, add `l` * chore: typos * Fleshed out title * build(npm): remove unused dependencies * build(npm): upgrade to latest stable contentful sdk * chore: Addressing David feedbak * fix(credentials): update to match the new space * chore: Addressing code review comments * chore: Addressing code review comments * chore: res -> response, req-> request * chore: include exactly what we need * chore: Address JPs comments * chore: Address JPs comments * chore: Address Fredericks comments * chore: Address Fredericks comments * fixup! chore: Address Fredericks comments * fixup! fixup! chore: Address Fredericks comments * fixup! fixup! fixup! chore: Address Fredericks comments * fixup! fixup! fixup! fixup! chore: Address Fredericks comments * fixup! fixup! fixup! fixup! fixup! chore: Address Fredericks comments * fixup! fixup! fixup! fixup! fixup! fixup! chore: Address Fredericks comments
75 lines
2.6 KiB
JavaScript
75 lines
2.6 KiB
JavaScript
const cheerio = require('cheerio')
|
|
const cookie = require('cookie')
|
|
const cookieParser = require('cookie-parser')
|
|
const request = require('supertest')
|
|
|
|
const app = require('../../app')
|
|
|
|
function getSettingsCookie (response) {
|
|
try {
|
|
const cookies = response.headers['set-cookie']
|
|
const settingsCookie = cookies.find((cookie) => cookie.startsWith('theExampleAppSettings='))
|
|
const parsedCookie = cookie.parse(settingsCookie)
|
|
return cookieParser.JSONCookie(parsedCookie.theExampleAppSettings)
|
|
} catch (err) {
|
|
throw new Error(`Settings cookie was not set or could not be parsed. ${err.message}`)
|
|
}
|
|
}
|
|
|
|
describe('settings', () => {
|
|
test('should render', () => {
|
|
return request(app).get('/settings')
|
|
.expect(200)
|
|
.then((response) => {
|
|
const $ = cheerio.load(response.text)
|
|
|
|
const title = $('main h1')
|
|
expect(title.text()).toBe('Settings')
|
|
|
|
const status = $('main .status-block.status-block--info')
|
|
expect(status.text()).toMatch(/Connected to space “.+”/)
|
|
|
|
const inputSpaceId = $('#input-space')
|
|
expect(inputSpaceId.val()).toBe(process.env.CF_SPACE)
|
|
|
|
const inputCda = $('#input-cda')
|
|
expect(inputCda.val()).toBe(process.env.CF_ACCESS_TOKEN)
|
|
|
|
const inputCpa = $('#input-cpa')
|
|
expect(inputCpa.val()).toBe(process.env.CF_PREVIEW_ACCESS_TOKEN)
|
|
|
|
const inputEditorialFeatures = $('#input-editorial-features')
|
|
expect(inputEditorialFeaturesponse.prop('checked')).toBeFalsy()
|
|
})
|
|
})
|
|
|
|
test('should have the editorial features enabled when query parameter is set and set cookie for it', () => {
|
|
return request(app).get('/settings?enable_editorial_features')
|
|
.expect(200)
|
|
.expect((response) => {
|
|
const cookie = getSettingsCookie(response)
|
|
if (!cookie.editorialFeatures) {
|
|
throw new Error('Did not set cookie value for editorial features')
|
|
}
|
|
|
|
if (cookie.space !== process.env.CF_SPACE) {
|
|
throw new Error('Did not set correct cookie value for SpaceID')
|
|
}
|
|
|
|
if (cookie.cda !== process.env.CF_ACCESS_TOKEN) {
|
|
throw new Error('Did not set correct cookie value for CDA access token')
|
|
}
|
|
|
|
if (cookie.cpa !== process.env.CF_PREVIEW_ACCESS_TOKEN) {
|
|
throw new Error('Did not set correct cookie value for CPA access token')
|
|
}
|
|
})
|
|
.then((response) => {
|
|
const $ = cheerio.load(response.text)
|
|
|
|
const inputEditorialFeatures = $('#input-editorial-features')
|
|
expect(inputEditorialFeaturesponse.prop('checked')).toBeTruthy()
|
|
})
|
|
})
|
|
})
|