mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
Add events test
This commit is contained in:
parent
8e9e84484f
commit
dab1dca5e8
@ -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);
|
||||
});
|
||||
|
34
unleash-server/test/eventApi.test.js
Normal file
34
unleash-server/test/eventApi.test.js
Normal file
@ -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);
|
||||
});
|
||||
|
||||
});
|
@ -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");
|
||||
}
|
||||
}
|
||||
};
|
@ -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);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user