Skip to content

Commit

Permalink
Ensure Like operations return a Predicate on parse()
Browse files Browse the repository at this point in the history
  • Loading branch information
jadrake75 committed Jul 30, 2017
1 parent 4aa5837 commit c96d021
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "odata-filter-parser",
"version": "0.2.12",
"version": "0.2.13",
"description": "Library for parsing and building OData filter strings",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/odata-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ var ODataParser = function() {

function buildLike(match, key) {
var right = (key === 'startsWith') ? match[2] + '*' : (key === 'endsWith') ? '*' + match[2] : '*' + match[2] + '*';
return {
return new Predicate({
subject: match[1],
operator: Operators.LIKE,
value: right
};
});
}

function parseFragment(filter) {
Expand Down
7 changes: 7 additions & 0 deletions test/odata-parser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
var superagent = require('superagent')
var expect = require('expect.js')
var parser = require("../src/odata-parser").Parser;
var Predicate = require("../src/odata-parser").Predicate;

describe('ODataParser Tests', function (done) {

Expand Down Expand Up @@ -160,6 +161,12 @@ describe('ODataParser Tests', function (done) {
expect( obj.operator).to.be.eql('like');
});

it('Verify like operations return a Predicate', function() {
var s = "contains(name,'predName')";
var obj = parser.parse(s);
expect( obj instanceof Predicate).to.be(true);
});

it('Parse datetimeoffset value', function() {
var s = "(purchased le datetimeoffset'2015-12-06T05:00:00.000Z')";
var obj = parser.parse(s);
Expand Down

0 comments on commit c96d021

Please sign in to comment.