Working draft of fixture creator. This is a functional implementation.
const uuid = require('uuid');
const ID = uuid();
function isObject(item) {
return typeof item === 'object' && !Array.isArray(item) && item !== null;
}
function handleNonObject(value, key) {
if(Array.isArray(value) && value[1] === ID) {
return handleOurOwn(value, key);
} else {
const result = {};
result[key] = value;
return result;
}
}
function handleOurOwn(value, key) {
let result;
switch (value[0]) {
case 'RANDOM_NUMBER':
result = 23;
break;
default:
break;
}
const returnValue = {};
returnValue[key] = result;
return returnValue;
}
function randomNumber() {
return [
'RANDOM_NUMBER',
ID,
]
}
function recursiveFunction(body) {
const keys = Object.keys(body);
keys.forEach(key => {
if(isObject(body[key])) {
console.log(`key \'${key}\' value is object`);
recursiveFunction(body[key])
} else {
handleNonObject(body[key], key)
}
})
}
function orchestrator(body) {
return recursiveFunction(body, result);
}
module.exports = {
orchestrator,
randomNumber,
}