diff --git a/lib/routes/admin-api/feature-schema.js b/lib/routes/admin-api/feature-schema.js index 8039aac420..85b75eb827 100644 --- a/lib/routes/admin-api/feature-schema.js +++ b/lib/routes/admin-api/feature-schema.js @@ -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(), }); diff --git a/lib/routes/admin-api/feature-schema.test.js b/lib/routes/admin-api/feature-schema.test.js index 6fedc516ef..4e6d553540 100644 --- a/lib/routes/admin-api/feature-schema.test.js +++ b/lib/routes/admin-api/feature-schema.test.js @@ -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); +});