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

recieve togglename to archive or revive via path

This commit is contained in:
sveisvei 2016-12-09 14:54:18 +01:00
parent d6bdc578c9
commit baf2c62f25
3 changed files with 12 additions and 14 deletions

View File

@ -77,16 +77,16 @@ class FeatureToggleStore {
.catch(err => logger.error('Could not update feature, error was: ', err)); .catch(err => logger.error('Could not update feature, error was: ', err));
} }
_archiveFeature (data) { _archiveFeature ({ name }) {
return this.db('features') return this.db(TABLE)
.where({ name: data.name }) .where({ name })
.update({ archived: 1 }) .update({ archived: 1 })
.catch(err => logger.error('Could not archive feature, error was: ', err)); .catch(err => logger.error('Could not archive feature, error was: ', err));
} }
_reviveFeature (data) { _reviveFeature ({ name }) {
return this.db('features') return this.db(TABLE)
.where({ name: data.name }) .where({ name })
.update({ archived: 0, enabled: 0 }) .update({ archived: 0, enabled: 0 })
.catch(err => logger.error('Could not archive feature, error was: ', err)); .catch(err => logger.error('Could not archive feature, error was: ', err));
} }

View File

@ -29,14 +29,14 @@ module.exports = function (app, config) {
}); });
}); });
app.post('/archive/revive', (req, res) => { app.post('/archive/revive/:name', (req, res) => {
req.checkBody('name', 'Name is required').notEmpty(); req.checkParams('name', 'Name is required').notEmpty();
validateRequest(req) validateRequest(req)
.then(() => eventStore.store({ .then(() => eventStore.store({
type: FEATURE_REVIVED, type: FEATURE_REVIVED,
createdBy: req.connection.remoteAddress, createdBy: req.connection.remoteAddress,
data: req.body, data: { name: req.params.name },
})) }))
.then(() => res.status(200).end()) .then(() => res.status(200).end())
.catch(error => handleErrors(req, res, error)); .catch(error => handleErrors(req, res, error));

View File

@ -23,8 +23,7 @@ test.serial('returns three archived toggles', async t => {
test.serial('revives a feature by name', async t => { test.serial('revives a feature by name', async t => {
const { request, destroy } = await setupApp('archive_serial'); const { request, destroy } = await setupApp('archive_serial');
return request return request
.post('/api/archive/revive') .post('/api/archive/revive/featureArchivedX')
.send({ name: 'featureArchivedX' })
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')
.expect(200) .expect(200)
.then(destroy); .then(destroy);
@ -33,8 +32,7 @@ test.serial('revives a feature by name', async t => {
test.serial('must set name when reviving toggle', async t => { test.serial('must set name when reviving toggle', async t => {
const { request, destroy } = await setupApp('archive_serial'); const { request, destroy } = await setupApp('archive_serial');
return request return request
.post('/api/archive/revive') .post('/api/archive/revive/')
.send({ name: '' }) .expect(404)
.expect(400)
.then(destroy); .then(destroy);
}); });