dbs-and-docs-test-bulkAddDriver

node v4.9.1
version: 22.0.0
endpointsharetweet
module.exports = bulkAddDriverTest; function findProblemRecords(record) { return record.ok === false; } function verifySchema(res, db) { var missingitems = []; db.allDocs({ include_docs: true, attachments: false, keys: res.id }, function(err, result_alldocs) { if (err) { return console.log(err); } // handle result if (result_alldocs) { if (result_alldocs.rows[2].doc.hasOwnProperty('firstName') !== true) { missingitems.push('firstName'); } if (result_alldocs.rows[2].doc.hasOwnProperty('suspended') !== true) { missingitems.push('suspended'); } if (result_alldocs.rows[2].doc.hasOwnProperty('violations') !== true) { missingitems.push('violations'); } if (result_alldocs.rows[2].doc.hasOwnProperty('plates') !== true) { missingitems.push('plates'); } console.log('Problem! The third document is missing the following information: ' + JSON.stringify(missingitems)); } }); } //b: { ok: true, index: 2, id: "3", db: db } function bulkAddDriverTest(a, b) { return function(err, res) { // what a and b are without having to have a global var ProblemRecords = res.find(findProblemRecords); if (err === a && ProblemRecords !== undefined) { console.log('Problem! At least one of your documents didn\'t save.: '); console.log(JSON.stringify(res)); } else if (err === a && ProblemRecords === undefined) { verifySchema(res, b.db); } else if (err === a && ProblemRecords === undefined && res[b.index].id === b.id) { console.log('Success! Done.'); console.log('response: ' + JSON.stringify(res)); } else { console.log('There was an error: ' + JSON.stringify(err)); } }; }
Loading…

no comments

    sign in to comment