1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: constraints should be part of toggle schema

This commit is contained in:
ivaosthu 2019-11-20 22:11:30 +01:00 committed by Ivar Conradi Østhus
parent d193a9842c
commit 459f49866c
2 changed files with 33 additions and 0 deletions

View File

@ -5,8 +5,18 @@ const { nameType } = require('./util');
const nameSchema = joi.object().keys({ name: nameType });
const constraintSchema = joi.object().keys({
contextName: joi.string(),
operator: joi.string(),
values: joi.array().items(joi.string()),
});
const strategiesSchema = joi.object().keys({
name: nameType,
constraints: joi
.array()
.allow(null)
.items(constraintSchema),
parameters: joi.object(),
});

View File

@ -93,3 +93,26 @@ test('variant overrides must have corect shape', async t => {
t.is(error.details[0].message, '"overrides" must be an array');
}
});
test('should keep constraints', t => {
const toggle = {
name: 'app.constraints',
enabled: false,
strategies: [
{
name: 'default',
constraints: [
{
contextName: 'environment',
operator: 'IN',
values: ['asd'],
},
],
},
],
};
const { value, error } = joi.validate(toggle, featureShema);
t.deepEqual(value, toggle);
t.falsy(error);
});