1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/test/featureApiSpec.js
Jari Bakken e52c1d16fe Begin work on running tests against the database:
* Add Travis postgresql setup.
* Replace "db mocks" with a before hook that creates the same data
  through the HTTP API.
* Reset DB and re-create all fixtures for each test. We'll need
  something  better here.
* CAVEAT: no concept of a dev vs test database. Running tests will
  clear data from the currently configured database.
2014-12-12 16:12:56 +01:00

65 lines
2.1 KiB
JavaScript

var assert = require('assert');
var specHelper = require('./specHelper');
var request = specHelper.request;
var stringify = function (o) { return JSON.stringify(o, null, ' '); };
describe('The features api', function () {
beforeEach(function (done) {
var d = function (err) { console.log('done', err); done.bind(null, err)(); };
specHelper.db.resetAndSetup()
.then(d.bind(null, null))
.catch(d);
});
it('returns three feature toggles', function (done) {
request
.get('/features')
.expect('Content-Type', /json/)
.expect(200)
.end(function (err, res) {
assert(res.body.features.length === 3, "expected 3 features, got " + stringify(res.body));
done();
});
});
it('gets a feature by name', function (done) {
request
.get('/features/featureX')
.expect('Content-Type', /json/)
.expect(200, done);
});
it('creates new feature toggle', function (done) {
request
.post('/features')
.send({name: 'com.test.feature', enabled: false})
.set('Content-Type', 'application/json')
.expect(201, done);
});
it('require new feature toggle to have a name', function (done) {
request
.post('/features')
.send({name: ''})
.set('Content-Type', 'application/json')
.expect(400, done);
});
it('can not change status of feature toggle that does not exist', function (done) {
request
.put('/features/should-not-exist')
.send({name: 'should-not-exist', enabled: false})
.set('Content-Type', 'application/json')
.expect(404, done);
});
it('can change status of feature toggle that does exist', function (done) {
request
.put('/features/featureY')
.send({name: 'featureY', enabled: true})
.set('Content-Type', 'application/json')
.expect(200, done);
});
});