I have several promises that I am trying to resolve using Promise.all asynchronously as below:
model1.find({ _id: params.id }).limit(1).
lean().then((data) => {
let promises = [];
let p1 = model2.find({ _id: '123' }).limit(1).lean().then((data) => {
return data;
})
promises.push(p1);
let p2 = model3.find({ _id: '789' }).limit(1).lean().then((data) => {
return data;
})
promises.push(p2);
let p3 = model4.find({ _id: '678' }).limit(1).lean().then((data) => {
return data;
})
promises.push(p3);
Promise.all(promises).then(data => {
data.forEach((entry) => {
let keys = Object.keys(entry);
result[keys[0]] = entry[keys[0]];
});
response.json(result);
})
})
How do I stub the above code using sinon and writing unit tests for them? Or any other library that I can use to unit-test the above code effectively