1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Adding test for /event/:name

This commit is contained in:
Gard Rimestad 2014-11-14 08:09:46 +01:00
parent a4cdec4fb1
commit 0a95ffe104
2 changed files with 51 additions and 1 deletions

View File

@ -31,4 +31,11 @@ describe('The event api', function () {
.expect(200, done);
});
it('returns events given a name', function (done) {
request
.get('/events/myname')
.expect('Content-Type', /json/)
.expect(200, done);
});
});

View File

@ -25,11 +25,47 @@ var events = [
"type": "feature-create",
"created_by": "me",
"data": {
"foo": "rab"
"foo": "rab",
"name": "myname"
}
}
];
var filterableEvents = [
{
"id": 1,
"created_at": 1414159948677,
"type": "feature-create",
"created_by": "me",
"data": {
"name": "foo"
}
},
{
"id": 2,
"created_at": 1414159948677,
"type": "feature-create",
"created_by": "me",
"data": {
"name": "bar"
}
},
{
"id": 3,
"created_at": 1414159948677,
"type": "feature-create",
"created_by": "me",
"data": {
"name": "myname"
}
}
];
function filterEventsByName(name) {
return filterableEvents.filter(function (n){return n.data.name===name;});
}
function getEvent(name) {
var eventFound;
events.forEach(function (event) {
@ -57,6 +93,12 @@ module.exports = {
});
},
getEventsFilterByName: function(name) {
return new Promise(function (resolve) {
resolve(filterEventsByName(name));
});
},
getEvent: function(name) {
var event = getEvent(name);
if(event) {
@ -65,4 +107,5 @@ module.exports = {
return Promise.reject("Event not found");
}
}
};