Skip to content

Commit

Permalink
Merge pull request #179 from agco/feature/allow-searching-null-values
Browse files Browse the repository at this point in the history
Feature/allow searching null values
  • Loading branch information
ShurakaiSoft authored Oct 14, 2016
2 parents 36b9714 + 71c2f44 commit 0bd9aca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/events-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = function (harvesterApp) {
var processWithHandlerT = throttle(processWithHandler, {
// call a maximum of 100 times per 1s window
window: 1,
limit: 100
limit: parseInt(_.get(harvesterApp, 'options.eventsReaderThrottleLimit'), 10) || 100
});


Expand Down
8 changes: 6 additions & 2 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,13 @@ function route(harvester, name, model, schema, routeOptions) {

//TODO: links.->"" is a mongodb storage issue, and should be in the mongodb adapter rather than here.
//allow multiple ids or other query params at the same time.
_.each(query, function (val, key, list) {
_.each(query, function (val, key) {
if (_.isString(val) && val.indexOf(',') != -1) {
query[key] = {$in: val.split(',')};
query[key] = {
$in: val.split(',').map(function (item) {
return item.length === 0 ? null : item;
})
};
}
});

Expand Down
1 change: 1 addition & 0 deletions test/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var config = require('./config.js');
function configureApp(harvesterApp) {
harvesterApp.resource('person', {
name: Joi.string().required().description('name'),
nickname: Joi.string().description('nickname'),
appearances: Joi.number().required().description('appearances'),
links: {
pets: ['pet'],
Expand Down
21 changes: 21 additions & 0 deletions test/filters.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
var _ = require('lodash');
var should = require('should');
var request = require('supertest');
var Promise = require('bluebird');
Expand All @@ -22,6 +23,26 @@ describe("filters", function () {
done();
});
});
it("should allow top-level resource filtering based on empty property", function (done) {
request(config.baseUrl).get('/people?nickname=,').expect('Content-Type', /json/).expect(200).end(function (error, response) {
should.not.exist(error);
var body = JSON.parse(response.text);
body.people.length.should.equal(2);
body.people.forEach(function (person) {
person.should.not.have.property('nickname');
});
done();
});
});
it("should allow top-level resource filtering based on empty property", function (done) {
request(config.baseUrl).get('/people?nickname=Pocahontas,').expect('Content-Type', /json/).expect(200).end(function (error, response) {
should.not.exist(error);
var body = JSON.parse(response.text);
body.people.length.should.equal(3);
_.map(body.people, 'nickname').sort().should.eql(['Pocahontas', undefined, undefined]);
done();
});
});

it("should allow top-level resource filtering based on a numeric value", function (done) {
request(config.baseUrl).get('/people?appearances=1934').expect('Content-Type', /json/).expect(200).end(function (error, response) {
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (function () {
{
"id": "600274a7-3862-45d7-8fca-e558cea1cf6d",
"name": "Catbert",
"nickname": "Pocahontas",
"appearances": 205
}
];
Expand Down

0 comments on commit 0bd9aca

Please sign in to comment.