mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
096c86d58b
This commit changes the features-tables: - drop columns 'strategy' and 'parameters' - add column 'strategies' of type json. - migrates existing strategy-mappings in to the new format. The idea is that the 'strategies' column should contain a json-array of strategy-configuration for the toggle: ``` [{ "name" : "strategy1", "parameters": { "name": "vale" } }] ``` To make sure to not break exiting clients the api is extended with a mapping layer (adding old fields to the json-respons, and mapping to the new format on create/update a feature toggle. this commit is first step in solving #102
146 lines
4.7 KiB
JavaScript
146 lines
4.7 KiB
JavaScript
'use strict';
|
|
const logger = require('../lib/logger');
|
|
const assert = require('assert');
|
|
const specHelper = require('./specHelper');
|
|
const request = specHelper.request;
|
|
const stringify = function (o) {
|
|
return JSON.stringify(o, null, ' ');
|
|
};
|
|
|
|
describe('The features api', () => {
|
|
beforeEach(done => {
|
|
specHelper.db.resetAndSetup()
|
|
.then(done.bind(null, null))
|
|
.catch(done);
|
|
});
|
|
|
|
it('returns three feature toggles', done => {
|
|
request
|
|
.get('/features')
|
|
.expect('Content-Type', /json/)
|
|
.expect(200)
|
|
.end((err, res) => {
|
|
assert(res.body.features.length === 3, `expected 3 features, got ${stringify(res.body)}`);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('gets a feature by name', done => {
|
|
request
|
|
.get('/features/featureX')
|
|
.expect('Content-Type', /json/)
|
|
.expect(200, done);
|
|
});
|
|
|
|
it('cant get feature that dose not exist', done => {
|
|
logger.setLevel('FATAL');
|
|
request
|
|
.get('/features/myfeature')
|
|
.expect('Content-Type', /json/)
|
|
.expect(404, done);
|
|
});
|
|
|
|
it('creates new feature toggle', done => {
|
|
request
|
|
.post('/features')
|
|
.send({ name: 'com.test.feature', enabled: false })
|
|
.set('Content-Type', 'application/json')
|
|
.expect(201, done);
|
|
});
|
|
|
|
it('creates new feature toggle with createdBy', done => {
|
|
logger.setLevel('FATAL');
|
|
request
|
|
.post('/features')
|
|
.send({ name: 'com.test.Username', enabled: false })
|
|
.set('Cookie', ['username=ivaosthu'])
|
|
.set('Content-Type', 'application/json')
|
|
.end(() => {
|
|
request
|
|
.get('/events')
|
|
.end((err, res) => {
|
|
assert.equal(res.body.events[0].createdBy, 'ivaosthu');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
it('require new feature toggle to have a name', done => {
|
|
logger.setLevel('FATAL');
|
|
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', done => {
|
|
logger.setLevel('FATAL');
|
|
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', done => {
|
|
logger.setLevel('FATAL');
|
|
request
|
|
.put('/features/featureY')
|
|
.send({ name: 'featureY', enabled: true })
|
|
.set('Content-Type', 'application/json')
|
|
.expect(200, done);
|
|
});
|
|
|
|
it('archives a feature by name', done => {
|
|
request
|
|
.delete('/features/featureX')
|
|
.expect(200, done);
|
|
});
|
|
|
|
it('can not archive unknown feature', done => {
|
|
request
|
|
.delete('/features/featureUnknown')
|
|
.expect(404, done);
|
|
});
|
|
|
|
it('refuses to create a feature with an existing name', done => {
|
|
request
|
|
.post('/features')
|
|
.send({ name: 'featureX' })
|
|
.set('Content-Type', 'application/json')
|
|
.expect(403, done);
|
|
});
|
|
|
|
describe('new strategies api', function () {
|
|
it('automatically map existing strategy to strategies array', function (done) {
|
|
request
|
|
.get('/features/featureY')
|
|
.expect('Content-Type', /json/)
|
|
.end(function (err, res) {
|
|
assert.equal(res.body.strategies.length, 1, 'expected strategy added to strategies');
|
|
assert.equal(res.body.strategy, res.body.strategies[0].name);
|
|
assert.deepEqual(res.body.parameters, res.body.strategies[0].parameters);
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('can add two strategies to a feature toggle', function (done) {
|
|
request
|
|
.put('/features/featureY')
|
|
.send({
|
|
name: 'featureY',
|
|
description: 'soon to be the #14 feature',
|
|
enabled: false,
|
|
strategies: [
|
|
{
|
|
name: 'baz',
|
|
parameters: { foo: 'bar' },
|
|
},
|
|
] })
|
|
.set('Content-Type', 'application/json')
|
|
.expect(200, done);
|
|
});
|
|
});
|
|
});
|