feat(editorial-features): switch logic to allow disabling via url params
This commit is contained in:
committed by
Benedikt Rötsch
parent
bccdb86f2c
commit
9783eda8a0
@@ -31,13 +31,15 @@ module.exports = async function settingsMiddleware (request, response, next) {
|
||||
updateCookie(response, SETTINGS_NAME, settings)
|
||||
}
|
||||
|
||||
// Allow enabling of editorial features via query parameters
|
||||
const { enable_editorial_features } = request.query
|
||||
if (enable_editorial_features !== undefined) { // eslint-disable-line camelcase
|
||||
delete request.query.enable_editorial_features
|
||||
settings.editorialFeatures = true
|
||||
// Allow enabling and disabling of editorial features via query parameters
|
||||
/* eslint-disable camelcase */
|
||||
const { editorial_features } = request.query
|
||||
if (typeof editorial_features !== 'undefined') {
|
||||
delete request.query.editorial_features
|
||||
settings.editorialFeatures = editorial_features === 'enabled'
|
||||
updateCookie(response, SETTINGS_NAME, settings)
|
||||
}
|
||||
/* eslint-enable camelcase */
|
||||
|
||||
// The space id needs to be available in the frontend for our example app
|
||||
response.cookie('space_id', settings.spaceId)
|
||||
|
||||
@@ -44,12 +44,12 @@ describe('settings', () => {
|
||||
})
|
||||
|
||||
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((response) => {
|
||||
const cookie = getSettingsCookie(response)
|
||||
if (!cookie.editorialFeatures) {
|
||||
throw new Error('Did not set cookie value for editorial features')
|
||||
if (cookie.editorialFeatures === false) {
|
||||
throw new Error('Editorial features value in cookie should not be false')
|
||||
}
|
||||
|
||||
if (cookie.spaceId !== process.env.CONTENTFUL_SPACE_ID) {
|
||||
@@ -71,4 +71,21 @@ describe('settings', () => {
|
||||
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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user