From 77a5adb616e09a58a7d00217106b086ca0bb0d17 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 29 Dec 2020 10:31:25 -0500 Subject: [PATCH] fix(tests): handle nested allOf blocks --- test/api.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/api.js b/test/api.js index 7d81b55c04..e4c28cfcef 100644 --- a/test/api.js +++ b/test/api.js @@ -117,7 +117,7 @@ describe('API', async () => { }], }); meta.config.allowTopicsThumbnail = 1; - meta.config.termsOfUse = 'I, for one, welcome our new test-drive overlords'; + meta.config.termsOfUse = 'I, for one, welcome our new test-driven overlords'; // Create a category const testCategory = await categories.create({ name: 'test' }); @@ -446,12 +446,20 @@ describe('API', async () => { let required = []; const additionalProperties = schema.hasOwnProperty('additionalProperties'); - if (schema.allOf) { - schema = schema.allOf.reduce((memo, obj) => { - required = required.concat(obj.required ? obj.required : Object.keys(obj.properties)); - memo = { ...memo, ...obj.properties }; - return memo; + function flattenAllOf(obj) { + return obj.reduce((memo, obj) => { + if (obj.allOf) { + obj = { properties: flattenAllOf(obj.allOf) }; + } else { + required = required.concat(obj.required ? obj.required : Object.keys(obj.properties)); + } + + return { ...memo, ...obj.properties }; }, {}); + } + + if (schema.allOf) { + schema = flattenAllOf(schema.allOf); } else if (schema.properties) { required = schema.required || Object.keys(schema.properties); schema = schema.properties;