From 1f5b1c192555f361c864e6147972b3aeba0d75ba Mon Sep 17 00:00:00 2001 From: sveisvei Date: Sun, 8 Jan 2017 20:04:46 +0100 Subject: [PATCH 1/3] add toggle endpoint --- lib/routes/feature.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/routes/feature.js b/lib/routes/feature.js index 458ee98d1d..356c846364 100644 --- a/lib/routes/feature.js +++ b/lib/routes/feature.js @@ -99,6 +99,23 @@ module.exports = function (app, config) { .catch(error => handleErrors(req, res, error)); }); + app.put('/features/:featureName/toggle', (req, res) => { + const featureName = req.params.featureName; + const userName = extractUser(req); + + featureToggleStore.getFeature(featureName) + .then((feature) => { + feature.enabled = !feature.enabled; + return eventStore.store({ + type: FEATURE_UPDATED, + createdBy: userName, + data: feature, + }); + }) + .then(() => res.status(200).end()) + .catch(error => handleErrors(req, res, error)); + }); + app.delete('/features/:featureName', (req, res) => { const featureName = req.params.featureName; const userName = extractUser(req); From a892c34be4e0599503051f40d2553d0f41a79638 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Mon, 9 Jan 2017 11:06:10 +0100 Subject: [PATCH 2/3] use post instead of put --- lib/routes/feature.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/feature.js b/lib/routes/feature.js index 356c846364..3629dc5692 100644 --- a/lib/routes/feature.js +++ b/lib/routes/feature.js @@ -99,7 +99,7 @@ module.exports = function (app, config) { .catch(error => handleErrors(req, res, error)); }); - app.put('/features/:featureName/toggle', (req, res) => { + app.post('/features/:featureName/toggle', (req, res) => { const featureName = req.params.featureName; const userName = extractUser(req); From 1b9d5b36e540397adf449525df489903dcc27a3e Mon Sep 17 00:00:00 2001 From: sveisvei Date: Mon, 9 Jan 2017 11:28:48 +0100 Subject: [PATCH 3/3] add simple e2e tests --- test/e2e/feature-api.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/e2e/feature-api.test.js b/test/e2e/feature-api.test.js index 7b00d0e51c..172e48840c 100644 --- a/test/e2e/feature-api.test.js +++ b/test/e2e/feature-api.test.js @@ -98,6 +98,24 @@ test.serial('can change status of feature toggle that does exist', async t => { .expect(200).then(destroy); }); +test.serial('can not toggle of feature that does not exist', async t => { + const { request, destroy } = await setupApp('feature_api_serial'); + logger.setLevel('FATAL'); + return request + .post('/features/should-not-exist/toggle') + .set('Content-Type', 'application/json') + .expect(404).then(destroy); +}); + +test.serial('can toggle a feature that does exist', async t => { + const { request, destroy } = await setupApp('feature_api_serial'); + logger.setLevel('FATAL'); + return request + .post('/features/featureY/toggle') + .set('Content-Type', 'application/json') + .expect(200).then(destroy); +}); + test.serial('archives a feature by name', async t => { const { request, destroy } = await setupApp('feature_api_serial'); return request