From dab1dca5e8928f9ecdeb4d477c72ef052c5dc8bc Mon Sep 17 00:00:00 2001 From: andsandv Date: Fri, 24 Oct 2014 16:15:59 +0200 Subject: [PATCH] Add events test --- .../scripts/generate-liquibase-artifact.js | 2 +- unleash-server/test/eventApi.test.js | 34 +++++++++++ unleash-server/test/eventDbMock.js | 60 ++++++++++++++++++- unleash-server/test/featureApiSpec.js | 1 + 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 unleash-server/test/eventApi.test.js diff --git a/unleash-server/scripts/generate-liquibase-artifact.js b/unleash-server/scripts/generate-liquibase-artifact.js index 2eacf4ac92..05a8b2f9f2 100755 --- a/unleash-server/scripts/generate-liquibase-artifact.js +++ b/unleash-server/scripts/generate-liquibase-artifact.js @@ -41,7 +41,7 @@ fs.readdir(sqlRoot, function (err, files) { Object.keys(changes).forEach(function (name) { var change = changes[name]; - var el = changeLog.ele('changeSet', {id: name, author: "unleash"}); + var el = changeLog.ele('changeSet', {id: name, author: 'unleash'}); el.ele('sql', {}, change.up); el.ele('rollback', {}, change.down); }); diff --git a/unleash-server/test/eventApi.test.js b/unleash-server/test/eventApi.test.js new file mode 100644 index 0000000000..6ad579d33f --- /dev/null +++ b/unleash-server/test/eventApi.test.js @@ -0,0 +1,34 @@ +var request = require('supertest'), + mockery = require('mockery'); + +describe('The event api', function () { + var server; + + before(function () { + mockery.enable({ + warnOnReplace: false, + warnOnUnregistered: false, + useCleanCache: true + }); + + mockery.registerSubstitute('./eventDb', '../test/eventDbMock'); + mockery.registerSubstitute('./featureDb', '../test/featureDbMock'); + + server = require('../server'); + request = request('http://localhost:' + server.app.get('port')); + }); + + after(function () { + mockery.disable(); + mockery.deregisterAll(); + server.server.close(); + }); + + it('returns events', function (done) { + request + .get('/events') + .expect('Content-Type', /json/) + .expect(200, done); + }); + +}); \ No newline at end of file diff --git a/unleash-server/test/eventDbMock.js b/unleash-server/test/eventDbMock.js index f617ed7c95..9d943270fc 100644 --- a/unleash-server/test/eventDbMock.js +++ b/unleash-server/test/eventDbMock.js @@ -1,4 +1,45 @@ -var Promise = require('bluebird'); +var Promise = require("bluebird"); + +var events = [ + { + "id": 1, + "created_at": 1414159948677, + "type": "feature-create", + "created_by": "me", + "data": { + + } + }, + { + "id": 2, + "created_at": 1414159948677, + "type": "feature-create", + "created_by": "me", + "data": { + "foo": "bar" + } + }, + { + "id": 3, + "created_at": 1414159948677, + "type": "feature-create", + "created_by": "me", + "data": { + "foo": "rab" + } + } +]; + +function getEvent(name) { + var eventFound; + events.forEach(function (event) { + if (event.name === name) { + eventFound = event; + } + }); + + return eventFound; +} function storeEvent() { return new Promise(function (resolve) { @@ -8,5 +49,20 @@ function storeEvent() { module.exports = { - store: storeEvent + store: storeEvent, + + getEvents: function() { + return new Promise(function (resolve) { + resolve(events); + }); + }, + + getEvent: function(name) { + var event = getEvent(name); + if(event) { + return Promise.resolve(event); + } else { + return Promise.reject("Event not found"); + } + } }; \ No newline at end of file diff --git a/unleash-server/test/featureApiSpec.js b/unleash-server/test/featureApiSpec.js index 927c5947ce..56b0d7f2dd 100644 --- a/unleash-server/test/featureApiSpec.js +++ b/unleash-server/test/featureApiSpec.js @@ -27,6 +27,7 @@ describe('The api', function () { it('returns three mocked feature toggles', function (done) { request .get('/features') + .expect('Content-Type', /json/) .expect(200, done); });