Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #87 from Shyp/throw-on-unknown-operator
Browse files Browse the repository at this point in the history
Throw an error if the operator is unknown
  • Loading branch information
particlebanana committed Mar 29, 2016
2 parents 998b9ef + ae8dfd0 commit da40666
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.PHONY: test test-unit install test-integration

ROOT=$(shell pwd)

install:
npm install

test: test-unit

test-unit:
Expand All @@ -12,4 +17,4 @@ test-integration:
ln -s $(ROOT) node_modules/sails-postgresql/node_modules/waterline-sequel
rm -rf node_modules/sails-mysql/node_modules/waterline-sequel
ln -s $(ROOT) node_modules/sails-mysql/node_modules/waterline-sequel
@NODE_ENV=test node test/integration/runnerDispatcher.js
@NODE_ENV=test node test/integration/runnerDispatcher.js
5 changes: 5 additions & 0 deletions sequel/lib/criteriaProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,11 @@ CriteriaProcessor.prototype.prepareCriterion = function prepareCriterion(key, va
}

break;

default:
var err = new Error('Unknown filtering operator: "' + key + "\". Should be 'startsWith', '>', 'contains' or similar");
err.operator = key;
throw err;
}

// Bump paramCount
Expand Down
10 changes: 9 additions & 1 deletion test/unit/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ describe('Sequel', function () {
});
});

describe('queries with an unknown operator', function () {
it('throws an error when the operator is unknown', function() {
var sequel = new Sequel(schema);
assert.throws(sequel.find.bind(sequel, 'bar', { id: { 'in': [ 1, 2 ] } }),
Error, "Unknown filtering operator: \"in\". Should be 'startsWith', '>', 'contains' or similar");
});
});

describe('.find() with schema name', function () {
var _options = _.extend({}, options, {schemaName: {'foo':'myschema','oddity':'anotherschema','bat':'public'}});
// Loop through the query objects and test them against the `.find()` method.
Expand All @@ -99,5 +107,5 @@ describe('Sequel', function () {
done();
});
});
});
});
});

0 comments on commit da40666

Please sign in to comment.