1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/packages/unleash-api/test/unit/routes/feature.test.js

74 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-08-23 01:29:47 +02:00
'use strict';
const supertest = require('supertest');
2016-08-23 01:29:47 +02:00
const BPromise = require('bluebird');
BPromise.promisifyAll(supertest);
const assert = require('assert');
const sinon = require('sinon');
let request;
let featureDb;
describe('Unit: The features api', () => {
beforeEach(done => {
featureDb = createFeatureDb();
const app = require('../../../app')({
baseUriPath: '',
db: sinon.stub(),
eventDb: sinon.stub(),
eventStore: sinon.stub(),
featureDb,
2016-08-23 01:29:47 +02:00
strategyDb: sinon.stub(),
});
request = supertest(app);
done();
});
it('should get empty getFeatures', (done) => {
request
.get('/features')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
assert(res.body.features.length === 0);
done();
});
});
it('should get one getFeature', (done) => {
featureDb.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
request
.get('/features')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
assert(res.body.features.length === 1);
done();
});
});
it('should add version numbers for /features', (done) => {
featureDb.addFeature( { name: 'test', strategies: [{ name: 'default' }] } );
request
.get('/features')
.expect('Content-Type', /json/)
.expect(200)
.end((err, res) => {
assert.equal(res.body.version, 1);
done();
});
});
2016-08-23 01:29:47 +02:00
});
function createFeatureDb () {
const _features = [];
2016-08-23 01:29:47 +02:00
return {
getFeatures: () => BPromise.resolve(_features),
addFeature: (feature) => _features.push(feature),
};
}