2016-04-24 22:41:37 +02:00
|
|
|
'use strict';
|
2016-05-01 22:53:09 +02:00
|
|
|
var logger = require('../lib/logger');
|
2014-12-05 17:20:17 +01:00
|
|
|
var assert = require('assert');
|
2014-11-25 14:41:11 +01:00
|
|
|
var specHelper = require('./specHelper');
|
2014-12-05 17:20:17 +01:00
|
|
|
var request = specHelper.request;
|
2016-04-24 22:41:37 +02:00
|
|
|
var stringify = function (o) {
|
|
|
|
return JSON.stringify(o, null, ' ');
|
|
|
|
};
|
2014-10-20 15:12:30 +02:00
|
|
|
|
2014-11-25 14:41:11 +01:00
|
|
|
describe('The features api', function () {
|
2014-12-05 17:20:17 +01:00
|
|
|
beforeEach(function (done) {
|
|
|
|
specHelper.db.resetAndSetup()
|
2014-12-09 14:44:25 +01:00
|
|
|
.then(done.bind(null, null))
|
|
|
|
.catch(done);
|
2014-12-05 17:20:17 +01:00
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
|
2014-12-05 17:20:17 +01:00
|
|
|
it('returns three feature toggles', function (done) {
|
2014-10-20 15:12:30 +02:00
|
|
|
request
|
|
|
|
.get('/features')
|
2014-10-24 16:15:59 +02:00
|
|
|
.expect('Content-Type', /json/)
|
2014-12-05 17:20:17 +01:00
|
|
|
.expect(200)
|
|
|
|
.end(function (err, res) {
|
|
|
|
assert(res.body.features.length === 3, "expected 3 features, got " + stringify(res.body));
|
|
|
|
done();
|
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
});
|
|
|
|
|
2014-11-25 15:28:08 +01:00
|
|
|
it('gets a feature by name', function (done) {
|
|
|
|
request
|
|
|
|
.get('/features/featureX')
|
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
|
2015-02-10 17:30:18 +01:00
|
|
|
it('cant get feature that dose not exist', function (done) {
|
2016-05-01 22:53:09 +02:00
|
|
|
logger.setLevel('FATAL');
|
2015-02-10 17:30:18 +01:00
|
|
|
request
|
2015-02-10 18:28:17 +01:00
|
|
|
.get('/features/myfeature')
|
2015-02-10 17:30:18 +01:00
|
|
|
.expect('Content-Type', /json/)
|
|
|
|
.expect(404, done);
|
|
|
|
});
|
|
|
|
|
2014-10-20 15:12:30 +02:00
|
|
|
it('creates new feature toggle', function (done) {
|
|
|
|
request
|
|
|
|
.post('/features')
|
2016-04-24 22:41:37 +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
|
|
|
|
2015-02-05 16:46:07 +01:00
|
|
|
it('creates new feature toggle with createdBy', function (done) {
|
2016-05-01 22:53:09 +02:00
|
|
|
logger.setLevel('FATAL');
|
2015-02-05 16:46:07 +01:00
|
|
|
request
|
|
|
|
.post('/features')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'com.test.Username', enabled: false })
|
2015-02-05 16:46:07 +01:00
|
|
|
.set('Cookie', ['username=ivaosthu'])
|
|
|
|
.set('Content-Type', 'application/json')
|
2016-04-24 22:41:37 +02:00
|
|
|
.end(function() {
|
|
|
|
request
|
|
|
|
.get('/events')
|
|
|
|
.end(function (err, res) {
|
|
|
|
assert.equal(res.body.events[0].createdBy, 'ivaosthu');
|
|
|
|
done();
|
|
|
|
});
|
2015-02-05 16:46:07 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-01 11:47:21 +01:00
|
|
|
it('require new feature toggle to have a name', function (done) {
|
2016-05-01 22:53:09 +02:00
|
|
|
logger.setLevel('FATAL');
|
2014-11-01 11:47:21 +01:00
|
|
|
request
|
|
|
|
.post('/features')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: '' })
|
2014-11-01 11:47:21 +01:00
|
|
|
.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) {
|
2016-05-01 22:53:09 +02:00
|
|
|
logger.setLevel('FATAL');
|
2014-10-21 16:02:23 +02:00
|
|
|
request
|
2014-11-14 12:56:23 +01:00
|
|
|
.put('/features/should-not-exist')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'should-not-exist', enabled: false })
|
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) {
|
2016-05-01 22:53:09 +02:00
|
|
|
logger.setLevel('FATAL');
|
2014-10-22 15:52:43 +02:00
|
|
|
request
|
2014-11-14 12:56:23 +01:00
|
|
|
.put('/features/featureY')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'featureY', enabled: true })
|
2014-10-22 15:52:43 +02:00
|
|
|
.set('Content-Type', 'application/json')
|
2014-11-14 12:56:23 +01:00
|
|
|
.expect(200, done);
|
2014-10-21 16:02:23 +02:00
|
|
|
});
|
|
|
|
|
2014-12-17 21:56:27 +01:00
|
|
|
it('archives a feature by name', function (done) {
|
|
|
|
request
|
|
|
|
.delete('/features/featureX')
|
|
|
|
.expect(200, done);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can not archive unknown feature', function (done) {
|
|
|
|
request
|
|
|
|
.delete('/features/featureUnknown')
|
|
|
|
.expect(404, done);
|
|
|
|
});
|
|
|
|
|
2015-02-10 17:19:32 +01:00
|
|
|
it('refuses to create a feature with an existing name', function (done) {
|
|
|
|
request
|
|
|
|
.post('/features')
|
2016-04-24 22:41:37 +02:00
|
|
|
.send({ name: 'featureX' })
|
2015-02-10 17:19:32 +01:00
|
|
|
.set('Content-Type', 'application/json')
|
|
|
|
.expect(403, done);
|
|
|
|
});
|
2015-02-05 16:46:07 +01:00
|
|
|
});
|