Skip to content

Commit

Permalink
User should not be allowed to post both 'strategy' and 'strategies' a…
Browse files Browse the repository at this point in the history
…t the same time

Relates #102
  • Loading branch information
ivarconr committed Feb 20, 2020
1 parent 1de0d0a commit 55bc634
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/unleash-api/lib/routes/feature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
};
20 changes: 20 additions & 0 deletions packages/unleash-api/test/featureApiSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 55bc634

Please sign in to comment.