Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit efa6055

Browse files
authored
fix cds.ql (#266)
1 parent f599206 commit efa6055

File tree

1 file changed

+60
-74
lines changed

1 file changed

+60
-74
lines changed

test/cds.ql.test.js

Lines changed: 60 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,6 @@ expect.one = (cqn) => !cqn.SELECT.distinct ? expect(cqn) : skip
1616
describe('cds.ql → cqn', () => {
1717
//
1818

19-
describe(`SELECT...`, () => {
20-
21-
it('should consistently handle *', () => {
22-
if (!cdr) return
23-
expect({
24-
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
25-
})
26-
.to.eql(CQL`SELECT * from Foo`)
27-
.to.eql(CQL`SELECT from Foo{*}`)
28-
.to.eql(SELECT('*').from(Foo))
29-
.to.eql(SELECT.from(Foo,['*']))
30-
})
31-
32-
33-
it('should consistently handle lists', () => {
34-
const ID = 11, args = [{ref:['foo']}, 'bar', 3]
35-
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
36-
expect(SELECT.from`Foo`.where `ID=${ID} and x in ${args}`).to.eql(cqn)
37-
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
38-
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
39-
})
40-
41-
})
42-
43-
4419
for (let each of ['SELECT', 'SELECT one', 'SELECT distinct']) {
4520
let SELECT; beforeEach(()=> SELECT = (
4621
each === 'SELECT distinct' ? cds.ql.SELECT.distinct :
@@ -285,46 +260,46 @@ describe('cds.ql → cqn', () => {
285260
).to.eql({
286261
SELECT: {
287262
from: { ref: ['Foo'] },
288-
where: cdr
289-
? [
290-
{ ref: ['ID'] },
291-
'=',
292-
{ val: ID },
293-
'and',
294-
{ ref: ['args'] },
295-
'in',
296-
{ list: args.map(val => ({ val })) },
297-
'and',
298-
{xpr:[
299-
{ ref: ['x'] },
300-
'like',
301-
{ val: '%x%' },
302-
'or',
303-
{ ref: ['y'] },
304-
'>=',
305-
{ val: 9 },
306-
]},
263+
where: cdr ? [
264+
{ ref: ['ID'] },
265+
'=',
266+
{ val: ID },
267+
'and',
268+
{ ref: ['args'] },
269+
'in',
270+
{ list: args.map(val => ({ val })) },
271+
'and',
272+
{
273+
xpr: [
274+
{ ref: ['x'] },
275+
'like',
276+
{ val: '%x%' },
277+
'or',
278+
{ ref: ['y'] },
279+
'>=',
280+
{ val: 9 },
307281
]
308-
: [
309-
{ ref: ['ID'] },
310-
'=',
311-
{ val: ID },
312-
'and',
313-
{ ref: ['args'] },
314-
'in',
315-
{ list: args.map(val => ({ val })) },
316-
'and',
317-
'(',
318-
{ ref: ['x'] },
319-
'like',
320-
{ val: '%x%' },
321-
'or',
322-
{ ref: ['y'] },
323-
'>=',
324-
{ val: 9 },
325-
')',
326-
],
327-
},
282+
},
283+
] : [
284+
{ ref: ['ID'] },
285+
'=',
286+
{ val: ID },
287+
'and',
288+
{ ref: ['args'] },
289+
'in',
290+
{ list: args.map(val => ({ val })) },
291+
'and',
292+
'(',
293+
{ ref: ['x'] },
294+
'like',
295+
{ val: '%x%' },
296+
'or',
297+
{ ref: ['y'] },
298+
'>=',
299+
{ val: 9 },
300+
')',
301+
],
302+
}
328303
})
329304

330305
// using CQL fragments -> uses cds.parse.expr
@@ -377,15 +352,6 @@ describe('cds.ql → cqn', () => {
377352
)
378353
})
379354

380-
it('should consistently handle lists', () => {
381-
if (!cdr) return
382-
const ID = 11, args = [{ref:['foo']}, "bar", 3]
383-
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
384-
expect(SELECT.from(Foo).where`ID=${ID} and x in ${args}`).to.eql(cqn)
385-
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
386-
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
387-
})
388-
389355
test('w/ sub selects', () => {
390356
// in where causes
391357
expect(SELECT.from(Foo).where({ x: SELECT('y').from('Bar') })).to.eql(
@@ -418,12 +384,32 @@ describe('cds.ql → cqn', () => {
418384
).to.eql(cqn)
419385
})
420386

421-
it('w/ plain SQL', () => {
387+
test('w/ plain SQL', () => {
422388
expect(SELECT.from(Books) + 'WHERE ...').to.eql(
423389
'SELECT * FROM capire_bookshop_Books WHERE ...'
424390
)
425391
})
426392

393+
it('should consistently handle *', () => {
394+
if (!cdr) return
395+
expect({
396+
SELECT: { from: { ref: ['Foo'] }, columns: ['*'] },
397+
})
398+
.to.eql(CQL`SELECT * from Foo`)
399+
.to.eql(CQL`SELECT from Foo{*}`)
400+
.to.eql(SELECT('*').from(Foo))
401+
.to.eql(SELECT.from(Foo,['*']))
402+
})
403+
404+
it('should consistently handle lists', () => {
405+
if (!cdr) return
406+
const ID = 11, args = [{ref:['foo']}, "bar", 3]
407+
const cqn = CQL`SELECT from Foo where ID=11 and x in (foo,'bar',3)`
408+
expect(SELECT.from(Foo).where`ID=${ID} and x in ${args}`).to.eql(cqn)
409+
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
410+
expect(SELECT.from(Foo).where({ ID, x:args })).to.eql(cqn)
411+
})
412+
427413
//
428414
})
429415
}

0 commit comments

Comments
 (0)