From 02533005577e21f3252241dec1f08666b9407ce5 Mon Sep 17 00:00:00 2001 From: D065023 Date: Tue, 26 Oct 2021 11:22:43 +0200 Subject: [PATCH] Changes in ql for cds version 5.6.0 --- test/cds.ql.test.js | 113 ++++++++++++++++++++++++++++++-------------- 1 file changed, 77 insertions(+), 36 deletions(-) diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index 81148750..1ff7a2b4 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -86,14 +86,24 @@ describe('cds.ql → cqn', () => { .to.eql(SELECT.from(Foo,{ID:11})) .to.eql(SELECT.from(Foo).byKey(11)) .to.eql(SELECT.from(Foo).byKey({ID:11})) - expect.one(cqn) - .to.eql({ - SELECT: { - one: true, - from: { ref: ['Foo'] }, - where: [{ ref: ['ID'] }, '=', { val: 11 }], - }, - }) + if (cds.version >= '5.6.0') { + expect.one(cqn) + .to.eql({ + SELECT: { + one: true, + ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }] }], + }, + }) + } else { + expect.one(cqn) + .to.eql({ + SELECT: { + one: true, + from: { ref: ['Foo'] }, + where: [{ ref: ['ID'] }, '=', { val: 11 }], + }, + }) + } }) @@ -131,15 +141,27 @@ describe('cds.ql → cqn', () => { // Test combination with key as second argument to .from expect(cqn = SELECT.from(Foo, 11, ['a'])) .to.eql(SELECT.from(Foo, 11, foo => foo.a)) - expect.one(cqn) - .to.eql({ - SELECT: { - one: true, - from: { ref: ['Foo'] }, - columns: [{ ref: ['a'] }], - where: [{ ref: ['ID'] }, '=', { val: 11 }], - }, - }) + + if (cds.version >= '5.6.0') { + expect.one(cqn) + .to.eql({ + SELECT: { + one: true, + from: { ref: [{ id: 'Foo', where: [{ ref: ['ID'] }, '=', { val: 11 }]}] }, + columns: [{ ref: ['a'] }] + }, + }) + } else { + expect.one(cqn) + .to.eql({ + SELECT: { + one: true, + from: { ref: ['Foo'] }, + columns: [{ ref: ['a'] }], + where: [{ ref: ['ID'] }, '=', { val: 11 }], + }, + }) + } }) @@ -551,21 +573,31 @@ describe('cds.ql → cqn', () => { describe(`UPDATE...`, () => { test('entity (..., )', () => { - expect(UPDATE(Books, 4711)) - .to.eql(UPDATE(Books, { ID: 4711 })) - .to.eql(UPDATE(Books).byKey(4711)) - .to.eql(UPDATE(Books).byKey({ ID: 4711 })) - .to.eql(UPDATE(Books).where({ ID: 4711 })) - .to.eql(UPDATE(Books).where(`ID=`, 4711)) - .to.eql(UPDATE.entity(Books, 4711)) - .to.eql(UPDATE.entity(Books, { ID: 4711 })) - // etc... - .to.eql({ + const cqnWhere = { UPDATE: { entity: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }], }, - }) + } + expect(UPDATE(Books).where({ ID: 4711 })) + .to.eql(UPDATE(Books).where(`ID=`, 4711)) + .to.eql(cqnWhere) + + const cqnKey = (cds.version >= '5.6.0') ? + { + UPDATE: { + entity: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }] }] } + } + } + : cqnWhere + expect(UPDATE(Books, 4711)) + .to.eql(UPDATE(Books, { ID: 4711 })) + .to.eql(UPDATE(Books).byKey(4711)) + .to.eql(UPDATE(Books).byKey({ ID: 4711 })) + .to.eql(UPDATE.entity(Books, 4711)) + .to.eql(UPDATE.entity(Books, { ID: 4711 })) + // etc... + .to.eql(cqnKey) }) /* @@ -616,20 +648,29 @@ describe('cds.ql → cqn', () => { describe(`DELETE...`, () => { test('from (..., )', () => { + const cqnWhere = { + DELETE: { + from: 'capire.bookshop.Books', + where: [{ ref: ['ID'] }, '=', { val: 4711 }], + }, + } + expect(DELETE.from(Books).where({ ID: 4711 })) + .to.eql(DELETE.from(Books).where(`ID=`, 4711)) + .to.eql(cqnWhere) + const cqnKey = (cds.version >= '5.6.0') ? + { + DELETE: { + from: { ref: [{ id: 'capire.bookshop.Books', where: [{ ref: ['ID'] }, '=', { val: 4711 }]}] } + }, + } : cqnWhere + expect(DELETE(Books, 4711)) .to.eql(DELETE(Books, { ID: 4711 })) .to.eql(DELETE.from(Books, 4711)) .to.eql(DELETE.from(Books, { ID: 4711 })) .to.eql(DELETE.from(Books).byKey(4711)) .to.eql(DELETE.from(Books).byKey({ ID: 4711 })) - .to.eql(DELETE.from(Books).where({ ID: 4711 })) - .to.eql(DELETE.from(Books).where(`ID=`, 4711)) - .to.eql({ - DELETE: { - from: 'capire.bookshop.Books', - where: [{ ref: ['ID'] }, '=', { val: 4711 }], - }, - }) + .to.eql(cqnKey) }) test('/w plain SQL', () => {