From 9783eda8a0e9b132a728671a2d6b74268745ae89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Mon, 5 Feb 2018 15:52:25 +0100 Subject: [PATCH] feat(editorial-features): switch logic to allow disabling via url params --- lib/settings.js | 12 +++++++----- test/integration/settings.test.js | 23 ++++++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/settings.js b/lib/settings.js index 366db17..b5d4a9d 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -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) diff --git a/test/integration/settings.test.js b/test/integration/settings.test.js index f14c56c..8146e30 100644 --- a/test/integration/settings.test.js +++ b/test/integration/settings.test.js @@ -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() + }) + }) })