Skip to content

Commit

Permalink
Include user information on revive
Browse files Browse the repository at this point in the history
Closes #327
  • Loading branch information
ivarconr committed Jun 25, 2018
1 parent 4b4effd commit a4fe53f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/routes/admin-api/archive.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 },
})
)
Expand Down
19 changes: 19 additions & 0 deletions lib/routes/admin-api/archive.test.js
Expand Up @@ -20,6 +20,7 @@ function getSetup() {
return {
base,
archiveStore: stores.featureToggleStore,
eventStore: stores.eventStore,
request: supertest(app),
};
}
Expand Down Expand Up @@ -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');
});
15 changes: 11 additions & 4 deletions test/fixtures/fake-event-store.js
@@ -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),
};
};

0 comments on commit a4fe53f

Please sign in to comment.