Merge pull request #1151 from strongloop/backport_1142

Continue _coerce after logical operators
This commit is contained in:
Amirali Jafarian 2016-10-26 13:51:08 -04:00 committed by GitHub
commit 9923ddb29b
2 changed files with 26 additions and 1 deletions

View File

@ -1570,7 +1570,8 @@ DataAccessObject._coerce = function(where) {
err.statusCode = 400;
throw err;
}
return where;
continue;
}
var DataType = props[p] && props[p].type;
if (!DataType) {

View File

@ -1445,6 +1445,16 @@ describe('DataAccessObject', function() {
assert.deepEqual(where, {or: [{age: 10}, {vip: true}]});
});
it('continues to coerce properties after a logical operator', function() {
var clause = {and: [{age: '10'}], vip: 'true'};
// Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
assert(Object.keys(clause)[0] === 'and', 'Unexpected key order.');
where = model._coerce(clause);
assert.deepEqual(where, {and: [{age: 10}], vip: true});
});
it('should throw if the where property is not an object', function() {
try {
// The where clause has to be an object
@ -1497,6 +1507,20 @@ describe('DataAccessObject', function() {
assert(error, 'An error should have been thrown');
});
it('throws an error when malformed logical operators follow valid logical clauses', function() {
var invalid = {and: [{x: 1}], or: 'bogus'};
// Key order is predictable but not guaranteed. We prefer false negatives (failure) to false positives.
assert(Object.keys(invalid)[0] !== 'or', 'Unexpected key order.');
try {
model._coerce(invalid);
} catch (err) {
error = err;
}
assert(error, 'An error should have been thrown');
});
it('should throw if filter property is not an object', function() {
var filter = null;
try {