New home of odata2cqn
This commit is contained in:
@@ -2,19 +2,13 @@ const { parse:{cql:CQL}, test:{expect}} = require("@sap/cds/lib")
|
||||
const { parser:{parse:OData} } = require("../lib/odata2cqn")
|
||||
|
||||
describe("$filter", () => {
|
||||
// logger can be omitted
|
||||
// afterEach(function () {
|
||||
// logParserResult(newParserRes, `${this.currentTest.title}-new`);
|
||||
// logParserResult(currentParserRes, `${this.currentTest.title}-cur`);
|
||||
// });
|
||||
|
||||
describe("comparing expressions", () => {
|
||||
|
||||
const types = {
|
||||
strings: "'some string'",
|
||||
'safe integers': 11,
|
||||
'unsafe integers': 2e53,
|
||||
decimals: 0.99,
|
||||
integers: 11,
|
||||
// decimals: 0.99, //> REVISIT: wait for compiler v2.0.4 ?
|
||||
// ...
|
||||
}
|
||||
it.each(Object.keys(types))("should support expressions with %s", (t) => {
|
||||
@@ -41,20 +35,21 @@ describe("$filter", () => {
|
||||
describe("logical expressions", () => {
|
||||
|
||||
it.each(['and','or'])("should support '%s'", (t) => {
|
||||
expect (OData(`Foo?$filter=bar lt 11 and name eq 'some name'`))
|
||||
.to.eql (CQL(`SELECT from Foo where bar < 11 and name = 'some name'`))
|
||||
expect (OData(`Foo?$filter=bar lt 11 ${t} name eq 'some name'`))
|
||||
.to.eql (CQL(`SELECT from Foo where bar < 11 ${t} name = 'some name'`))
|
||||
})
|
||||
|
||||
it("should support 'not'", () => {
|
||||
// REVISIT: We need to check with the Node.js team why they translated that to the equivalent of:
|
||||
// not name like concat('%','sunny','%') escape '^'
|
||||
expect (OData(`Foo?$filter= not contains(name,'sunny')`))
|
||||
.to.eql (CQL(`SELECT from Foo where not name like '%sunny%'`))
|
||||
.to.eql (CQL(`SELECT from Foo where not contains(name,'sunny')`))
|
||||
});
|
||||
|
||||
// REVISIT: wait for compiler v2
|
||||
it("should support group expr", () => {
|
||||
expect (OData(`Foo?$filter= (unitPrice lt 11 and length(name) eq 12) or name eq 'Restless and Wild'`))
|
||||
.to.eql (CQL(`SELECT from Foo where (unitPrice < 11 and length(name) = 12) or name = 'Restless and Wild'`))
|
||||
expect (OData(`Foo?$filter= (unitPrice gt 11 and length(name) eq 12) or name eq 'Restless and Wild'`))
|
||||
.to.eql (CQL(`SELECT from Foo where (unitPrice > 11 and length(name) = 12) or name = 'Restless and Wild'`))
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,17 +57,17 @@ describe("$filter", () => {
|
||||
|
||||
it("should support contains", () => {
|
||||
expect (OData(`Foo?$filter= contains(name,'sunny')`))
|
||||
.to.eql (CQL(`SELECT from Foo where name like '%sunny%'`))
|
||||
.to.eql (CQL(`SELECT from Foo where contains(name,'sunny')`))
|
||||
});
|
||||
|
||||
it("should support startswith", () => {
|
||||
expect (OData(`Foo?$filter= startswith(name,'sunny')`))
|
||||
.to.eql (CQL(`SELECT from Foo where name like 'sunny%'`))
|
||||
.to.eql (CQL(`SELECT from Foo where startswith(name,'sunny')`))
|
||||
});
|
||||
|
||||
it("should support endswith", () => {
|
||||
expect (OData(`Foo?$filter= endswith(name,'sunny')`))
|
||||
.to.eql (CQL(`SELECT from Foo where name like '%sunny'`))
|
||||
.to.eql (CQL(`SELECT from Foo where endswith(name,'sunny')`))
|
||||
});
|
||||
|
||||
it("should support length", () => {
|
||||
@@ -82,7 +77,7 @@ describe("$filter", () => {
|
||||
|
||||
it("should support indexof", () => {
|
||||
expect (OData(`Foo?$filter= indexof(name,'x') eq 11`))
|
||||
.to.eql (CQL(`SELECT from Foo where locate(name,'x') = 11`))
|
||||
.to.eql (CQL(`SELECT from Foo where indexof(name,'x') = 11`))
|
||||
});
|
||||
|
||||
it("should support substring", () => {
|
||||
@@ -92,12 +87,12 @@ describe("$filter", () => {
|
||||
|
||||
it.each(['tolower','toupper','trim'])("should support '%s'", (fn) => {
|
||||
expect (OData(`Foo?$filter= ${fn}(name) eq 'foo'`))
|
||||
.to.eql (CQL(`SELECT from Foo where ${fn.replace(/^to/,'')}(name) = 'foo'`))
|
||||
.to.eql (CQL(`SELECT from Foo where ${fn}(name) = 'foo'`))
|
||||
});
|
||||
|
||||
it("should support 'day'", () => {
|
||||
expect (OData(`Foo?$filter= day(name) eq 11`))
|
||||
.to.eql (CQL(`SELECT from Foo where dayofmonth(name) = 11`))
|
||||
.to.eql (CQL(`SELECT from Foo where day(name) = 11`))
|
||||
});
|
||||
|
||||
it("should support concat", () => {
|
||||
@@ -106,4 +101,5 @@ describe("$filter", () => {
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user