diff --git a/unleash-server/lib/eventStore.js b/unleash-server/lib/eventStore.js index 6e8ca3087e..d099936f69 100644 --- a/unleash-server/lib/eventStore.js +++ b/unleash-server/lib/eventStore.js @@ -1,6 +1,5 @@ var util = require('util'); var EventEmitter = require('events').EventEmitter; -var events = require('./events'); function EventStore() { EventEmitter.call(this); @@ -8,8 +7,16 @@ function EventStore() { util.inherits(EventStore, EventEmitter); -EventStore.prototype.create = function (obj) { - this.emit(events.featureCreated, obj); +EventStore.prototype.create = function (eventType, user, eventData) { + var event = { + id: 1, + created: "2014-08-01 12:22:00", + type: eventType, + user: user, + data: eventData + }; + + this.emit(event.type, event); }; module.exports = new EventStore(); \ No newline at end of file diff --git a/unleash-server/lib/eventType.js b/unleash-server/lib/eventType.js new file mode 100644 index 0000000000..045b579145 --- /dev/null +++ b/unleash-server/lib/eventType.js @@ -0,0 +1,3 @@ +module.exports = { + featureCreated : 'feature-created' +}; \ No newline at end of file diff --git a/unleash-server/lib/events.js b/unleash-server/lib/events.js deleted file mode 100644 index c58133a422..0000000000 --- a/unleash-server/lib/events.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - featureCreated : 'featureCreated' -}; \ No newline at end of file diff --git a/unleash-server/lib/featureApi.js b/unleash-server/lib/featureApi.js index 6edfd4edb6..83eb5a4f85 100644 --- a/unleash-server/lib/featureApi.js +++ b/unleash-server/lib/featureApi.js @@ -1,11 +1,10 @@ -var db = require('./db'); -var eventStore = require('./eventStore'); +var db = require('./db') + eventStore = require('./eventStore'), + eventType = require('./eventType'); module.exports = function (app) { app.get('/features', function (req, res) { - // TODO svelovla, fix this - eventStore.create({name: 'testing method'}); db.getFeatures().then(function (features) { res.json({features: features}); }); @@ -22,15 +21,16 @@ module.exports = function (app) { }); app.post('/features', function (req, res) { - var newFeature = req.body; + var newFeature = req.body, + user = req.connection.remoteAddress; db.getFeature(newFeature.name).then(function (feature) { if (feature) { + //Todo: error-msg: feature name is already in use res.status(403).end(); } else { - db.addFeature(newFeature).then(function () { - res.status(201).end(); - }); + eventStore.create(eventType.featureCreated, user, newFeature); + res.status(201).end(); } }); }); diff --git a/unleash-server/test/eventStoreSpec.js b/unleash-server/test/eventStoreSpec.js index e5d84a0801..70a89191e6 100644 --- a/unleash-server/test/eventStoreSpec.js +++ b/unleash-server/test/eventStoreSpec.js @@ -1,21 +1,24 @@ var assert = require('assert'); -var events = require('../lib/events'); +var eventType = require('../lib/eventType'); var eventStore = require('../lib/eventStore'); describe('EventStore', function () { describe('#create()', function () { it('should emit event', function (done) { - eventStore.once(events.featureCreated, function (x) { + eventStore.once(eventType.featureCreated, function (x) { assert(x); done(); } ); - eventStore.create({ + + var eventData = { 'name': 'mail-server.validate-email-addresses', 'enabled': false, 'strategy': 'default', 'description': 'Feature description' - }); + }; + + eventStore.create(eventType.featureCreated,"ole",eventData); }); }); });