Prep for cleaning up cds.ql

This commit is contained in:
Daniel
2021-08-25 20:41:13 +02:00
committed by Daniel Hutzel
parent 839048d87c
commit f58376607a

View File

@@ -4,7 +4,7 @@ const CQL = ([cql]) => cds.parse.cql(cql)
const Foo = { name: 'Foo' } const Foo = { name: 'Foo' }
const Books = { name: 'capire.bookshop.Books' } const Books = { name: 'capire.bookshop.Books' }
const { parse:cdr } = cds.ql const { cdr } = cds.ql
// while jest has 'test' as alias to 'it', mocha doesn't // while jest has 'test' as alias to 'it', mocha doesn't
if (!global.test) global.test = it if (!global.test) global.test = it
@@ -111,7 +111,7 @@ describe('cds.ql → cqn', () => {
.to.eql(SELECT.from(Foo).columns('*')) .to.eql(SELECT.from(Foo).columns('*'))
.to.eql(SELECT.from(Foo).columns((foo) => foo('*'))) .to.eql(SELECT.from(Foo).columns((foo) => foo('*')))
.to.eql({ .to.eql({
SELECT: { from: { ref: ['Foo'] }, columns: [cdr ? '*' : { ref: ['*'] }] }, SELECT: { from: { ref: ['Foo'] }, columns: [{ ref: ['*'] }] },
}) })
if (cdr) expect(parsed).to.eql(fluid) if (cdr) expect(parsed).to.eql(fluid)
@@ -162,7 +162,7 @@ describe('cds.ql → cqn', () => {
.to.eql({ .to.eql({
SELECT: { SELECT: {
from: { ref: ['Foo'] }, from: { ref: ['Foo'] },
columns: [{ ref: ['a'] }, { ref: ['b'] }, cdr ? '*' : { ref: ['*'] }], columns: [{ ref: ['a'] }, { ref: ['b'] }, { ref: ['*'] }],
}, },
}) })
}) })
@@ -182,7 +182,7 @@ describe('cds.ql → cqn', () => {
SELECT: { SELECT: {
from: { ref: ['Foo'] }, from: { ref: ['Foo'] },
columns: [ columns: [
cdr ? '*' : { ref: ['*'] }, { ref: ['*'] },
{ ref: ['x'] }, { ref: ['x'] },
{ ref: ['car'], expand: ['*'] }, { ref: ['car'], expand: ['*'] },
{ {
@@ -246,19 +246,37 @@ describe('cds.ql → cqn', () => {
expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({ expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({
SELECT: { SELECT: {
from: { ref: ['Foo'] }, from: { ref: ['Foo'] },
where: [ where: cdr ? [
{ ref: ['x'] },
'=',
{ val: 1 },
'and',
// '(',
{xpr:[
{ ref: ['y'] },
'=',
{ val: 2 },
'or',
{ ref: ['z'] },
'=',
{ val: 3 },
]},
// ')',
] : [
{ ref: ['x'] }, { ref: ['x'] },
'=', '=',
{ val: 1 }, { val: 1 },
'and', 'and',
'(', '(',
{ ref: ['y'] }, // {xpr:[
'=', { ref: ['y'] },
{ val: 2 }, '=',
'or', { val: 2 },
{ ref: ['z'] }, 'or',
'=', { ref: ['z'] },
{ val: 3 }, '=',
{ val: 3 },
// ]},
')', ')',
], ],
}, },
@@ -280,9 +298,8 @@ describe('cds.ql → cqn', () => {
).to.eql({ ).to.eql({
SELECT: { SELECT: {
from: { ref: ['Foo'] }, from: { ref: ['Foo'] },
where: cds.version >= '5.3.0' where: cdr
? [ ? [
// '(', //> this one is not required
{ ref: ['ID'] }, { ref: ['ID'] },
'=', '=',
{ val: ID }, { val: ID },
@@ -291,18 +308,17 @@ describe('cds.ql → cqn', () => {
'in', 'in',
{ list: args.map(val => ({ val })) }, { list: args.map(val => ({ val })) },
'and', 'and',
'(', //> this one is missing, and that's changing the logic -> that's a BUG {xpr:[
{ ref: ['x'] }, { ref: ['x'] },
'like', 'like',
{ val: '%x%' }, { val: '%x%' },
'or', 'or',
{ ref: ['y'] }, { ref: ['y'] },
'>=', '>=',
{ val: 9 }, { val: 9 },
')', ]},
] ]
: [ : [
// '(', //> this one is not required
{ ref: ['ID'] }, { ref: ['ID'] },
'=', '=',
{ val: ID }, { val: ID },
@@ -311,14 +327,14 @@ describe('cds.ql → cqn', () => {
'in', 'in',
{ val: args }, { val: args },
'and', 'and',
'(', //> this one is missing, and that's changing the logic -> that's a BUG '(',
{ ref: ['x'] }, { ref: ['x'] },
'like', 'like',
{ val: '%x%' }, { val: '%x%' },
'or', 'or',
{ ref: ['y'] }, { ref: ['y'] },
'>=', '>=',
{ val: 9 }, { val: 9 },
')', ')',
], ],
}, },