1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

Include user information on revive

Closes #327
This commit is contained in:
Ivar Conradi Østhus 2018-06-25 18:34:23 +02:00
parent 4b4effda19
commit 5ad2e246e5
3 changed files with 34 additions and 5 deletions

View File

@ -6,6 +6,7 @@ const logger = require('../../logger')('/admin-api/archive.js');
const { FEATURE_REVIVED } = require('../../event-type');
const ValidationError = require('../../error/validation-error');
const validateRequest = require('../../error/validate-request');
const extractUser = require('../../extract-user');
const handleErrors = (req, res, error) => {
switch (error.constructor) {
@ -33,11 +34,13 @@ module.exports.router = function(config) {
router.post('/revive/:name', (req, res) => {
req.checkParams('name', 'Name is required').notEmpty();
const userName = extractUser(req);
validateRequest(req)
.then(() =>
eventStore.store({
type: FEATURE_REVIVED,
createdBy: req.connection.remoteAddress,
createdBy: userName,
data: { name: req.params.name },
})
)

View File

@ -20,6 +20,7 @@ function getSetup() {
return {
base,
archiveStore: stores.featureToggleStore,
eventStore: stores.eventStore,
request: supertest(app),
};
}
@ -67,3 +68,21 @@ test('should revive toggle', t => {
return request.post(`${base}/api/admin/archive/revive/${name}`).expect(200);
});
test('should create event when reviving toggle', async t => {
t.plan(4);
const name = 'name1';
const { request, base, archiveStore, eventStore } = getSetup();
archiveStore.addArchivedFeature({
name,
strategies: [{ name: 'default' }],
});
await request.post(`${base}/api/admin/archive/revive/${name}`);
const events = await eventStore.getEvents();
t.is(events.length, 1);
t.is(events[0].type, 'feature-revived');
t.is(events[0].data.name, name);
t.is(events[0].createdBy, 'unknown');
});

View File

@ -1,6 +1,13 @@
'use strict';
module.exports = () => ({
store: () => Promise.resolve(),
getEvents: () => Promise.resolve([]),
});
module.exports = () => {
const events = [];
return {
store: event => {
events.push(event);
Promise.resolve();
},
getEvents: () => Promise.resolve(events),
};
};