-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfilter.test.js
63 lines (61 loc) · 1.49 KB
/
filter.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Transformations of infix filter expressions
* TODO: Move cluttered tests on filters to this file
*/
'use strict'
const cqn4sql = require('../../lib/cqn4sql')
const cds = require('@sap/cds')
const { expect } = cds.test
describe('filter expressions', () => {
let model
beforeAll(async () => {
model = await cds.load(__dirname + '/../bookshop/db/schema').then(cds.linked)
})
describe('on entity ref in from clause', () => {
it('flatten managed assoc; rhs is the assoc', () => {
expect(
cqn4sql(
CQL`
SELECT from bookshop.Books[ID = genre] { ID }
`,
model,
),
).to.deep.equal(
CQL`
SELECT from bookshop.Books as Books { Books.ID }
where Books.ID = Books.genre_ID
`,
)
})
it('flatten managed assoc lhs; rhs is val', () => {
expect(
cqn4sql(
CQL`
SELECT from bookshop.Books[genre = 1] { ID }
`,
model,
),
).to.deep.equal(
CQL`
SELECT from bookshop.Books as Books { Books.ID }
where Books.genre_ID = 1
`,
)
})
it('flatten managed assoc lhs; rhs is ref', () => {
expect(
cqn4sql(
CQL`
SELECT from bookshop.Books[genre = ID] { ID }
`,
model,
),
).to.deep.equal(
CQL`
SELECT from bookshop.Books as Books { Books.ID }
where Books.genre_ID = Books.ID
`,
)
})
})
})