Skip to content

Commit

Permalink
Merge pull request #9 from AParks/fix-not-exists
Browse files Browse the repository at this point in the history
fix null matching on objects with null id
  • Loading branch information
A Parks committed Mar 13, 2018
2 parents ef01e35 + 694bd71 commit 8035beb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -308,7 +308,9 @@ var znFilterMatcher = (function() {
} else if (recordValue.id !== undefined) {
recordValue = recordValue.id;
}
} else if (recordValue === null || recordValue === undefined) {
}

if (recordValue === null || recordValue === undefined) {
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "zn-filter-matcher",
"version": "1.2.2",
"version": "1.2.3",
"description": "Zengine Filter Matcher",
"main": "index.js",
"scripts": {
Expand Down
42 changes: 42 additions & 0 deletions tests/index-spec.js
Expand Up @@ -66,6 +66,27 @@ describe('znFilterMatcher', function() {

});

it('should return true with null object', function() {

record.field1 = {
id: null,
name: null
};

filter = {
and: [
{
prefix: '',
attribute: 'field1',
value: null
}
]
};

expect(znFilterMatcher.recordMatchesFilter(record, filter)).toBe(true);

});

});

/**
Expand Down Expand Up @@ -117,6 +138,27 @@ describe('znFilterMatcher', function() {

});

it('should return true with null object', function() {

record.field1 = {
id: null,
name: null
};

filter = {
and: [
{
prefix: 'not',
attribute: 'field1',
value: 'null'
}
]
};

expect(znFilterMatcher.recordMatchesFilter(record, filter)).toBe(false);

});

});

/**
Expand Down

0 comments on commit 8035beb

Please sign in to comment.