Comparing version 2.1.2 to 2.2.0
@@ -29,7 +29,41 @@ 'use strict' | ||
var target = this.value.execute(options.context, '<find in ' + this.collection + '>'), | ||
that = this, | ||
collection = options.db.collection(this.collection) | ||
if ('_id' in target) { | ||
this._executeWithId(target, collection, options, done) | ||
} else { | ||
this._executeWithoutId(target, collection, options, done) | ||
} | ||
} | ||
Find.prototype._executeWithId = function (target, collection, options, done) { | ||
var that = this | ||
collection.findOne({ | ||
_id: target._id | ||
}, function (err, doc) { | ||
if (err) { | ||
return done(err) | ||
} | ||
try { | ||
check(doc, target, options.strict, options.ignoredFindKeys) | ||
} catch (e) { | ||
console.log('\n-----\n' + | ||
'\x1b[1;32mDocument with id ' + target._id + ' in ' + that.collection + ':\x1b[0m\n' + | ||
stringify(doc, true, e.path) + '\n' + | ||
'\x1b[1;32mTarget document:\x1b[0m\n' + | ||
stringify(target, true, e.path) + '\n' + | ||
'-----\n') | ||
return done(new Error('Document mismatch in ' + that.collection)) | ||
} | ||
done() | ||
}) | ||
} | ||
Find.prototype._executeWithoutId = function (target, collection, options, done) { | ||
var that = this | ||
collection.find().toArray(function (err, docs) { | ||
var found, lastError | ||
var errorPaths = [], | ||
found | ||
@@ -45,3 +79,3 @@ if (err) { | ||
} catch (e) { | ||
lastError = e.path | ||
errorPaths.push(e.path) | ||
return false | ||
@@ -54,7 +88,7 @@ } | ||
'\x1b[1;32mDocuments in ' + that.collection + ':\x1b[0m\n' + | ||
docs.map(function (doc) { | ||
return stringify(doc, true, lastError) | ||
docs.map(function (doc, i) { | ||
return stringify(doc, true, errorPaths[i]) | ||
}).join('\n---\n') + '\n' + | ||
'\x1b[1;32mTarget document:\x1b[0m\n' + | ||
stringify(target, true, lastError) + '\n' + | ||
stringify(target, true) + '\n' + | ||
'-----\n') | ||
@@ -61,0 +95,0 @@ return done(new Error('No document found in ' + that.collection)) |
{ | ||
"name": "api-test", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"author": "Sitegui <sitegui@sitegui.com.br>", | ||
@@ -5,0 +5,0 @@ "description": "API testing made simple", |
@@ -8,2 +8,4 @@ # Database insertion | ||
base // this should not alter base | ||
### user2 in User | ||
base | ||
@@ -15,2 +17,6 @@ ## Test | ||
error: null | ||
a: 'Hello' | ||
a: 'Hello' | ||
### Find in User | ||
user // Find by id | ||
### Find in User | ||
base // Find any that match everything |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65058
1902