mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix(tests): handle nested allOf blocks
This commit is contained in:
20
test/api.js
20
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;
|
||||
|
||||
Reference in New Issue
Block a user