Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Equals Expression and tolower OData function #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ export class Visitor{
this.Visit(node.value.left, context);
this.Visit(node.value.right, context);

if (context.identifier) context.query[context.identifier] = context.literal;
// using object with $eq instead of just value assigned to identifier we resolve an issue with OData: not (documentStatus eq 'OPEN')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the not (...) test case ensures we do not regress back and break your feature.

if (context.identifier) context.query[context.identifier] = { $eq: context.literal };
delete context.identifier;
delete context.literal;
}
Expand Down Expand Up @@ -288,6 +289,12 @@ export class Visitor{
case "startswith":
context.query[context.identifier] = new RegExp("^" + context.literal, "gi");
break;
case "tolower":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have any plans to add a test case for this?

// mongoDb is case insensitive as default, so it should resolve 99% cases I hope - better than exception I think?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove "I hope - better than exception I think?" I think we agree 😃

// $toLower function is implemented only for agregation in MongoDb
// using object with $eq instead of just value assigned to identifier we resolve an issue with OData: not (documentStatus eq 'OPEN')
context.query[context.identifier] = { $eq: context.literal };
break;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these indent issues?

default:
throw new Error("Method call not implemented.")
}
Expand Down
28 changes: 14 additions & 14 deletions test/visitor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,55 +22,55 @@ describe("mongodb visitor", () => {
})

it("expression 5.1.1.6.1: NullValue eq null", () => {
expect(f).to.deep.eql({ NullValue: null })
expect(f).to.deep.eql({ NullValue: { $eq: null } })
})

it("expression 5.1.1.6.1: TrueValue eq true", () => {
expect(f).to.deep.eql({ TrueValue: true })
expect(f).to.deep.eql({ TrueValue: { $eq: true } })
})

it("expression 5.1.1.6.1: FalseValue eq false", () => {
expect(f).to.deep.eql({ FalseValue: false })
expect(f).to.deep.eql({ FalseValue: { $eq: false } })
})

it("expression 5.1.1.6.1: IntegerValue lt -128", () => {
expect(f).to.deep.eql({ IntegerValue: { $lt: -128 } })
})

it("expression 5.1.1.6.1: DecimalValue eq 34.95", () => {
expect(f).to.deep.eql({ DecimalValue: 34.95 })
expect(f).to.deep.eql({ DecimalValue: { $eq: 34.95 } })
})

it("expression 5.1.1.6.1: StringValue eq 'Say Hello,then go'", () => {
expect(f).to.deep.eql({ StringValue: 'Say Hello,then go' })
expect(f).to.deep.eql({ StringValue: { $eq: 'Say Hello,then go' } })
})

xit("expression 5.1.1.6.1: DurationValue eq duration'P12DT23H59M59.999999999999S'", () => {
expect(f).to.deep.eql({ DurationValue: 1033199000 })
expect(f).to.deep.eql({ DurationValue: { $eq: 1033199000 } })
})

it("expression 5.1.1.6.1: DateValue eq 2012-12-03", () => {
expect(f).to.deep.eql({ DateValue: '2012-12-03' })
expect(f).to.deep.eql({ DateValue: { $eq: '2012-12-03' } })
})

it("expression 5.1.1.6.1: DateTimeOffsetValue eq 2012-12-03T07:16:23Z", () => {
expect(f).to.deep.eql({ DateTimeOffsetValue: new Date('2012-12-03T07:16:23Z') })
expect(f).to.deep.eql({ DateTimeOffsetValue: { $eq: new Date('2012-12-03T07:16:23Z') } })
})

it("expression 5.1.1.6.1: GuidValue eq 01234567-89ab-cdef-0123-456789abcdef", () => {
expect(f).to.deep.eql({ GuidValue: '01234567-89ab-cdef-0123-456789abcdef' })
expect(f).to.deep.eql({ GuidValue: { $eq: '01234567-89ab-cdef-0123-456789abcdef' } })
})

it("expression 5.1.1.6.1: Int64Value eq 0", () => {
expect(f).to.deep.eql({ Int64Value: 0 })
expect(f).to.deep.eql({ Int64Value: { $eq: 0 } })
})

it("expression 5.1.1.6.1: A eq INF", () => {
expect(f).to.deep.eql({ A: Infinity })
expect(f).to.deep.eql({ A: { $eq: Infinity } })
})

it("expression 5.1.1.6.1: A eq 0.31415926535897931e1", () => {
expect(f).to.deep.eql({ A: 0.31415926535897931e1 })
expect(f).to.deep.eql({ A: { $eq: 0.31415926535897931e1 } })
})

it("expression 5.1.1.1.2: A ne 1", () => {
Expand All @@ -94,11 +94,11 @@ describe("mongodb visitor", () => {
})

it("expression: A/b eq 1", () => {
expect(f).to.deep.eql({ 'A.b': 1 })
expect(f).to.deep.eql({ 'A.b': { $eq: 1 } })
})

it("expression 5.1.1.3: (A/b eq 2) or (B/c lt 4) and ((E gt 5) or (E lt -1))", () => {
expect(f).to.deep.eql({ $or: [{ 'A.b': 2 }, { $and: [{ 'B.c': { $lt: 4 } }, { $or: [{ E: { $gt: 5 } }, { E: { $lt: -1 } }] }] }] })
expect(f).to.deep.eql({ $or: [{ 'A.b': { $eq: 2 } }, { $and: [{ 'B.c': { $lt: 4 } }, { $or: [{ E: { $gt: 5 } }, { E: { $lt: -1 } }] }] }] })
})

it("expression 5.1.1.4.1: contains(A, 'BC')", () => {
Expand Down