mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
0546100556
relates to #102
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
'use strict';
|
|
|
|
const supertest = require('supertest');
|
|
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,
|
|
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();
|
|
});
|
|
});
|
|
});
|
|
|
|
function createFeatureDb () {
|
|
const _features = [];
|
|
return {
|
|
getFeatures: () => BPromise.resolve(_features),
|
|
addFeature: (feature) => _features.push(feature),
|
|
};
|
|
}
|