From 3c860d7bcee9dd10f4f3d52b1cfcf1a838aac325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Fri, 30 Oct 2020 16:40:29 +0100 Subject: [PATCH] fix: constriants must have at least one value defined closes #640 --- lib/routes/admin-api/feature-schema.js | 16 ++++++++++------ lib/routes/admin-api/feature-schema.test.js | 8 +++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/routes/admin-api/feature-schema.js b/lib/routes/admin-api/feature-schema.js index e48d784cf2..5b94e52ae5 100644 --- a/lib/routes/admin-api/feature-schema.js +++ b/lib/routes/admin-api/feature-schema.js @@ -8,12 +8,16 @@ const nameSchema = joi.object().keys({ name: nameType }); const constraintSchema = joi.object().keys({ contextName: joi.string(), operator: joi.string(), - values: joi.array().items( - joi - .string() - .min(1) - .max(100), - ), + values: joi + .array() + .items( + joi + .string() + .min(1) + .max(100), + ) + .min(1) + .optional(), }); const strategiesSchema = joi.object().keys({ diff --git a/lib/routes/admin-api/feature-schema.test.js b/lib/routes/admin-api/feature-schema.test.js index c51a0724c9..79df0bbdaa 100644 --- a/lib/routes/admin-api/feature-schema.test.js +++ b/lib/routes/admin-api/feature-schema.test.js @@ -220,7 +220,9 @@ test('should not accept empty list of constraint values', t => { ], }; - const { value, error } = featureShema.validate(toggle); - t.deepEqual(value, toggle); - t.falsy(error); + const { error } = featureShema.validate(toggle); + t.deepEqual( + error.details[0].message, + '"strategies[0].constraints[0].values" must contain at least 1 items', + ); });