From b8e04027d5fd309814ecb7d4ec5bc2362d4875d0 Mon Sep 17 00:00:00 2001 From: Daniel Hutzel Date: Fri, 16 Sep 2022 14:55:38 +0200 Subject: [PATCH] Added few cds.ql tests (#402) --- test/cds.ql.test.js | 75 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 12 deletions(-) diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index c9f3f6dc..9165cfbd 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -411,18 +411,69 @@ describe('cds.ql → cqn', () => { ] }}) - 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} - ] - }}) + const ql_with_groups_fix = !!cds.ql.Query.prototype.flat + if (ql_with_groups_fix) { + + expect ( + SELECT.from(Foo).where({x:1}).or({y:2}).and({z:3}) + ).to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {ref:['x']}, '=', {val:1}, + 'or', + {ref:['y']}, '=', {val:2}, + 'and', + {ref:['z']}, '=', {val:3}, + ] + }}) + + expect ( + SELECT.from(Foo).where({x:1,or:{y:2}}).and({z:3}) + ).to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {xpr:[ + {ref:['x']}, '=', {val:1}, + 'or', + {ref:['y']}, '=', {val:2}, + ]}, + 'and', + {ref:['z']}, '=', {val:3}, + ] + }}) + + expect ( + SELECT.from(Foo).where({a:1}).or({x:1,or:{y:2}}).and({z:3}) + ).to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {ref:['a']}, '=', {val:1}, + 'or', + {xpr:[ + {ref:['x']}, '=', {val:1}, + 'or', + {ref:['y']}, '=', {val:2}, + ]}, + 'and', + {ref:['z']}, '=', {val:3}, + ] + }}) + + expect ( + SELECT.from(Foo).where({x:1,or:{y:2}}) + ).to.eql ({ SELECT: { + from: {ref:['Foo']}, + where: [ + {xpr:[ + {ref:['x']}, '=', {val:1}, + 'or', + {ref:['y']}, '=', {val:2}, + ]} + ] + }}) + + } + expect ( SELECT.from(Foo).where({x:1,and:{y:2}}).or({z:3})