mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
User should not be allowed to post both 'strategy' and 'strategies' at the same time
Relates #102
This commit is contained in:
parent
1de0d0a737
commit
55bc634b66
@ -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);
|
req.checkBody('name', 'Name must match format ^[0-9a-zA-Z\\.\\-]+$').matches(/^[0-9a-zA-Z\\.\\-]+$/i);
|
||||||
|
|
||||||
validateRequest(req)
|
validateRequest(req)
|
||||||
|
.then(validateFormat)
|
||||||
.then(validateUniqueName)
|
.then(validateUniqueName)
|
||||||
.then(() => eventStore.create({
|
.then(() => eventStore.create({
|
||||||
type: eventType.featureCreated,
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -141,5 +141,25 @@ describe('The features api', () => {
|
|||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.expect(200, done);
|
.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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user