feat(editorial-features): switch logic to allow disabling via url params

This commit is contained in:
Benedikt Rötsch
2018-02-05 15:52:25 +01:00
committed by Benedikt Rötsch
parent bccdb86f2c
commit 9783eda8a0
2 changed files with 27 additions and 8 deletions

View File

@@ -31,13 +31,15 @@ module.exports = async function settingsMiddleware (request, response, next) {
updateCookie(response, SETTINGS_NAME, settings) updateCookie(response, SETTINGS_NAME, settings)
} }
// Allow enabling of editorial features via query parameters // Allow enabling and disabling of editorial features via query parameters
const { enable_editorial_features } = request.query /* eslint-disable camelcase */
if (enable_editorial_features !== undefined) { // eslint-disable-line camelcase const { editorial_features } = request.query
delete request.query.enable_editorial_features if (typeof editorial_features !== 'undefined') {
settings.editorialFeatures = true delete request.query.editorial_features
settings.editorialFeatures = editorial_features === 'enabled'
updateCookie(response, SETTINGS_NAME, settings) updateCookie(response, SETTINGS_NAME, settings)
} }
/* eslint-enable camelcase */
// The space id needs to be available in the frontend for our example app // The space id needs to be available in the frontend for our example app
response.cookie('space_id', settings.spaceId) response.cookie('space_id', settings.spaceId)

View File

@@ -44,12 +44,12 @@ describe('settings', () => {
}) })
test('should have the editorial features enabled when query parameter is set and set cookie for it', () => { 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') return request(app).get('/settings?editorial_features=enabled')
.expect(200) .expect(200)
.expect((response) => { .expect((response) => {
const cookie = getSettingsCookie(response) const cookie = getSettingsCookie(response)
if (!cookie.editorialFeatures) { if (cookie.editorialFeatures === false) {
throw new Error('Did not set cookie value for editorial features') throw new Error('Editorial features value in cookie should not be false')
} }
if (cookie.spaceId !== process.env.CONTENTFUL_SPACE_ID) { if (cookie.spaceId !== process.env.CONTENTFUL_SPACE_ID) {
@@ -71,4 +71,21 @@ describe('settings', () => {
expect(inputEditorialFeatures.prop('checked')).toBeTruthy() expect(inputEditorialFeatures.prop('checked')).toBeTruthy()
}) })
}) })
test('should have the editorial features disabled when query parameter is set and set cookie for it', () => {
return request(app).get('/settings?editorial_features=disabled')
.expect(200)
.expect((response) => {
const cookie = getSettingsCookie(response)
if (cookie.editorialFeatures === true) {
throw new Error('Editorial features value in cookie should not be true')
}
})
.then((response) => {
const $ = cheerio.load(response.text)
const inputEditorialFeatures = $('#input-editorial-features')
expect(inputEditorialFeatures.prop('checked')).toBeFalsy()
})
})
}) })