diff --git a/packages/unleash-api/lib/routes/feature.js b/packages/unleash-api/lib/routes/feature.js index 38d2cd1722..a5c6bb082f 100644 --- a/packages/unleash-api/lib/routes/feature.js +++ b/packages/unleash-api/lib/routes/feature.js @@ -32,6 +32,7 @@ module.exports = function (app, config) { req.checkBody('name', 'Name must match format ^[0-9a-zA-Z\\.\\-]+$').matches(/^[0-9a-zA-Z\\.\\-]+$/i); validateRequest(req) + .then(validateFormat) .then(validateUniqueName) .then(() => eventStore.create({ type: eventType.featureCreated, @@ -102,4 +103,12 @@ module.exports = function (app, config) { }); }); } + + function validateFormat (req) { + if (req.body.strategy && req.body.strategies) { + return BPromise.reject(new ValidationError('Cannot use both "strategy" and "strategies".')); + } + + return BPromise.resolve(req); + } }; diff --git a/packages/unleash-api/test/featureApiSpec.js b/packages/unleash-api/test/featureApiSpec.js index 4f348b7bfd..0dc7ab8537 100644 --- a/packages/unleash-api/test/featureApiSpec.js +++ b/packages/unleash-api/test/featureApiSpec.js @@ -141,5 +141,25 @@ describe('The features api', () => { .set('Content-Type', 'application/json') .expect(200, done); }); + + it('should not be allowed to post both strategy and strategies', function (done) { + logger.setLevel('FATAL'); + request + .post('/features') + .send({ + name: 'featureConfusing', + description: 'soon to be the #14 feature', + enabled: false, + strategy: 'baz', + parameters: {}, + strategies: [ + { + name: 'baz', + parameters: { foo: 'bar' }, + }, + ] }) + .set('Content-Type', 'application/json') + .expect(400, done); + }); }); });