1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-14 00:19:16 +01:00

Merge pull request #199 from Unleash/add-toggle-ep

add toggle endpoint
This commit is contained in:
Sveinung Røsaker 2017-01-09 11:34:59 +01:00 committed by GitHub
commit 839aeb01a6
2 changed files with 35 additions and 0 deletions

View File

@ -99,6 +99,23 @@ module.exports = function (app, config) {
.catch(error => handleErrors(req, res, error));
});
app.post('/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);

View File

@ -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