From 08f409af730edee994c18e44bd220d8cc2028c4d Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Tue, 31 Aug 2021 18:05:22 +0200 Subject: [PATCH] more (#267) --- test/cds.ql.test.js | 60 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index f9cda7f3..b3cdb59c 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -180,11 +180,10 @@ describe('cds.ql → cqn', () => { }) }) - if (each !== 'SELECT') return test('with nested inlines', () => { // SELECT from Foo { *, x, bar.*, car{*}, boo { *, moo.zoo } } - expect( + expect.plain( SELECT.from (Foo, foo => { foo.bar `*`, foo.bar `.*`, //> leading dot indicates inline @@ -204,6 +203,10 @@ describe('cds.ql → cqn', () => { }) }) + })} + + describe ('SELECT where...', ()=>{ + it('should correctly handle { ... and:{...} }', () => { expect(SELECT.from(Foo).where({ x: 1, and: { y: 2, or: { z: 3 } } })).to.eql({ SELECT: { @@ -245,6 +248,58 @@ describe('cds.ql → cqn', () => { }) }) + test ('where, and, or', ()=>{ + expect ( + SELECT.from(Foo).where({x:1,and:{y:2}}) + ).to.eql ( + CQL`SELECT from Foo where x=1 and y=2` + ) .to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {ref:['x']}, '=', {val:1}, + 'and', + {ref:['y']}, '=', {val:2} + ] + }}) + + expect ( + SELECT.from(Foo).where({x:1,or:{y:2}}) + ).to.eql ( + CQL`SELECT from Foo where x=1 or y=2` + ).to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {ref:['x']}, '=', {val:1}, + 'or', + {ref:['y']}, '=', {val:2} + ] + }}) + + expect ( + SELECT.from(Foo).where({x:1,and:{y:2}}).or({z:3}) + ).to.eql ( + CQL`SELECT from Foo where x=1 and y=2 or z=3` + ) + + if (cdr) expect ( + SELECT.from(Foo).where({x:1}).and({y:2,or:{z:3}}) + ).to.eql ( + CQL`SELECT from Foo where x=1 and ( y=2 or z=3 )` + ) + + if (cdr) expect ( + SELECT.from(Foo).where({1:1}).and({x:1,or:{x:2}}).and({y:2,or:{z:3}}) + ).to.eql ( + CQL`SELECT from Foo where 1=1 and ( x=1 or x=2 ) and ( y=2 or z=3 )` + ) + + if (cdr) expect ( + SELECT.from(Foo).where({x:1,or:{x:2}}).and({y:2,or:{z:3}}) + ).to.eql ( + CQL`SELECT from Foo where ( x=1 or x=2 ) and ( y=2 or z=3 )` + ) + }) + test('where ( ... cql | {x:y} )', () => { const args = [`foo`, "'bar'", 3] const ID = 11 @@ -412,7 +467,6 @@ describe('cds.ql → cqn', () => { // }) -} describe(`INSERT...`, () => { test('entries ({a,b}, ...)', () => {