tests(api): Add sync method to api objects

This commit is contained in:
Blade Barringer
2016-01-16 21:50:54 -06:00
parent 87d4c68bea
commit 96f6bbfb0c
6 changed files with 45 additions and 20 deletions

View File

@@ -66,6 +66,20 @@ export async function updateDocument (collectionName, doc, update) {
});
}
export async function getDocument (collectionName, doc) {
let db = await connectToMongo();
let collection = db.collection(collectionName);
return new Promise((resolve) => {
collection.findOne({ _id: doc._id }, (lookupErr, found) => {
if (lookupErr) throw new Error(`Error looking up ${collectionName}: ${lookupErr}`);
db.close();
resolve(found);
});
});
}
export function connectToMongo () {
return new Promise((resolve, reject) => {
mongo.connect(DB_URI, (err, db) => {