2014-10-23 12:03:46 +02:00
|
|
|
var request = require('supertest'),
|
2014-10-23 14:13:17 +02:00
|
|
|
mockery = require('mockery');
|
2014-10-20 15:12:30 +02:00
|
|
|
|
|
|
|
describe('The api', function () {
|
|
|
|
var server;
|
|
|
|
|
|
|
|
before(function () {
|
2014-10-23 12:03:46 +02:00
|
|
|
mockery.enable({
|
|
|
|
warnOnReplace: false,
|
|
|
|
warnOnUnregistered: false,
|
|
|
|
useCleanCache: true
|
|
|
|
});
|
|
|
|
|
|
|
|
mockery.registerSubstitute('./eventDb', '../test/eventDbMock');
|
2014-10-23 13:51:37 +02:00
|
|
|
mockery.registerSubstitute('./featureDb', '../test/featureDbMock');
|
2014-10-23 12:03:46 +02:00
|
|
|
|
2014-10-20 15:12:30 +02:00
|
|
|
server = require('../server');
|
2014-10-23 14:13:17 +02:00
|
|
|
request = request('http://localhost:' + server.app.get('port'));
|
2014-10-20 15:12:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
after(function () {
|
2014-10-23 12:03:46 +02:00
|
|
|
mockery.disable();
|
|
|
|
mockery.deregisterAll();
|
2014-10-20 15:12:30 +02:00
|
|
|
server.server.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns three mocked feature toggles', function (done) {
|
|
|
|
request
|
|
|
|
.get('/features')
|
2014-10-24 16:15:59 +02:00
|
|
|
.expect('Content-Type', /json/)
|
2014-10-20 15:12:30 +02:00
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates new feature toggle', function (done) {
|
|
|
|
request
|
|
|
|
.post('/features')
|
2014-10-22 15:52:43 +02:00
|
|
|
.send({name: 'com.test.feature', 'enabled': false})
|
2014-10-20 15:12:30 +02:00
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(201, done);
|
|
|
|
});
|
2014-10-21 16:02:23 +02:00
|
|
|
|
2014-11-01 11:47:21 +01:00
|
|
|
it('require new feature toggle to have a name', function (done) {
|
|
|
|
request
|
|
|
|
.post('/features')
|
|
|
|
.send({name: ''})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(400, done);
|
|
|
|
});
|
|
|
|
|
2014-11-10 17:10:39 +01:00
|
|
|
it('can not change status of feature toggle that does not exist', function (done) {
|
2014-10-21 16:02:23 +02:00
|
|
|
request
|
2014-10-22 15:52:43 +02:00
|
|
|
.patch('/features/shouldNotExsist')
|
2014-10-21 16:02:23 +02:00
|
|
|
.send({
|
2014-10-22 15:52:43 +02:00
|
|
|
'field': 'enabled',
|
|
|
|
'value': true
|
2014-10-21 16:02:23 +02:00
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
2014-10-22 15:52:43 +02:00
|
|
|
.expect(404, done);
|
|
|
|
});
|
|
|
|
|
2014-11-10 17:10:39 +01:00
|
|
|
it('can change status of feature toggle that does exist', function (done) {
|
2014-10-22 15:52:43 +02:00
|
|
|
request
|
|
|
|
.patch('/features/featureY')
|
|
|
|
.send({
|
|
|
|
'field': 'enabled',
|
|
|
|
'value': true
|
|
|
|
})
|
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(202, done);
|
2014-10-21 16:02:23 +02:00
|
|
|
});
|
|
|
|
|
2014-10-20 15:12:30 +02:00
|
|
|
});
|