(pythagora, req)
| 222 | } |
| 223 | |
| 224 | async function prepareDB(pythagora, req) { |
| 225 | await cleanupDb(pythagora); |
| 226 | |
| 227 | const testReq = await pythagora.getRequestMockDataById(req); |
| 228 | if (!testReq) return; |
| 229 | |
| 230 | let uniqueIds = []; |
| 231 | for (const data of testReq.intermediateData) { |
| 232 | if (data.type !== 'mongodb') continue; |
| 233 | let insertData = []; |
| 234 | for (let doc of data.preQueryRes) { |
| 235 | if (!uniqueIds.includes(doc._id)) { |
| 236 | uniqueIds.push(doc._id); |
| 237 | insertData.push(jsonObjToMongo(doc)); |
| 238 | } |
| 239 | } |
| 240 | if (insertData.length) await pythagora.mongoClient.db(PYTHAGORA_DB).collection(data.collection).insertMany(insertData); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | function extractDataFromMongoRes(mongoResult) { |
| 245 | // todo refactor to add path to mongoResult inside src/const/mongodb.js for each method |
no test coverage detected