mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-22 23:42:54 +01:00
test: additional logic to allow multi-typing in schema type
This commit is contained in:
@@ -659,10 +659,15 @@ describe('API', async () => {
|
|||||||
case 'boolean':
|
case 'boolean':
|
||||||
assert.strictEqual(typeof response[prop], 'boolean', `"${prop}" was expected to be a boolean, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
assert.strictEqual(typeof response[prop], 'boolean', `"${prop}" was expected to be a boolean, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
||||||
break;
|
break;
|
||||||
case 'object':
|
case 'object': {
|
||||||
assert.strictEqual(typeof response[prop], 'object', `"${prop}" was expected to be an object, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
let valid = ['object'];
|
||||||
|
if (schema[prop].additionalProperties && schema[prop].additionalProperties.oneOf) {
|
||||||
|
valid = schema[prop].additionalProperties.oneOf.map(({ type }) => type);
|
||||||
|
}
|
||||||
|
assert(valid.includes(typeof response[prop]), `"${prop}" was expected to be an object, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
||||||
compare(schema[prop], response[prop], method, path, context ? [context, prop].join('.') : prop);
|
compare(schema[prop], response[prop], method, path, context ? [context, prop].join('.') : prop);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case 'array':
|
case 'array':
|
||||||
assert.strictEqual(Array.isArray(response[prop]), true, `"${prop}" was expected to be an array, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
assert.strictEqual(Array.isArray(response[prop]), true, `"${prop}" was expected to be an array, but was ${typeof response[prop]} instead (path: ${method} ${path}, context: ${context})`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user