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:
parent
d193a9842c
commit
459f49866c
@ -5,8 +5,18 @@ const { nameType } = require('./util');
|
|||||||
|
|
||||||
const nameSchema = joi.object().keys({ name: nameType });
|
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({
|
const strategiesSchema = joi.object().keys({
|
||||||
name: nameType,
|
name: nameType,
|
||||||
|
constraints: joi
|
||||||
|
.array()
|
||||||
|
.allow(null)
|
||||||
|
.items(constraintSchema),
|
||||||
parameters: joi.object(),
|
parameters: joi.object(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -93,3 +93,26 @@ test('variant overrides must have corect shape', async t => {
|
|||||||
t.is(error.details[0].message, '"overrides" must be an array');
|
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);
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user