1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-09 00:18:00 +01:00

#8 mocked api respons

This commit is contained in:
svelovla 2014-10-20 15:12:30 +02:00 committed by Ivar Conradi Østhus
parent c09ad0b8a9
commit 290a124aef
4 changed files with 92 additions and 16 deletions

View File

@ -1,5 +1,41 @@
module.exports = function (app) {
app.get('/features', function (req, res) {
res.send('some nice json features here!');
var featuresMock = require('./featuresMock');
function getFeature(name) {
var featureFound;
featuresMock.forEach(function (feature) {
if (feature.name === name) {
featureFound = feature;
}
});
};
return featureFound;
}
module.exports = function (app) {
app.get('/features', function (req, res) {
res.json(featuresMock);
});
app.get('/features/:id', function (req, res) {
var feature = getFeature(req.params.id);
if (feature) {
res.json(feature);
} else {
res.json(404, {error: 'Could not find feature'});
}
});
app.post('/features', function (req, res) {
var newFeature = req.body;
if (!getFeature(newFeature.name)) {
featuresMock.push(newFeature);
res.status(201).end();
} else {
res.status(500).end();
}
});
};

View File

@ -0,0 +1,23 @@
module.exports = [
{
"name": "featureX",
"status": "on",
"strategy": "default"
},
{
"name": "featureY",
"status": "off",
"strategy": "baz",
"parameters": {
"foo": "bar"
}
},
{
"name": "featureZ",
"status": "on",
"strategy": "baz",
"parameters": {
"foo": "rab"
}
}
];

View File

@ -1,12 +0,0 @@
var assert = require('assert');
describe('The api', function () {
beforeEach(function () {
//
});
it('returns all toggles', function (done) {
done();
assert(true);
});
});

View File

@ -0,0 +1,29 @@
var request = require('supertest');
request = request('http://localhost:4242');
describe('The api', function () {
var server;
before(function () {
server = require('../server');
});
after(function () {
server.server.close();
});
it('returns three mocked feature toggles', function (done) {
request
.get('/features')
.expect(200, done);
});
it('creates new feature toggle', function (done) {
request
.post('/features')
.send({name: 'featureAss', 'status': 'off'})
.set('Content-Type', 'application/json')
.expect(201, done);
});
});