-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpassport.test.js
More file actions
60 lines (53 loc) · 2.09 KB
/
Copy pathpassport.test.js
File metadata and controls
60 lines (53 loc) · 2.09 KB
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
process.env.SAP_PASSPORT = 'true'
// CDS v10 enables scheduling by default; its periodic outbox reads run in
// their own transactions and cause spurious SAP_PASSPORT set/reset pairs on
// the connection, breaking the deterministic _count assertions below. The
// `no-scheduling` profile (requires.scheduling: false) in test/bookshop/.cdsrc.json
// disables it.
const cds = require('@sap/cds')
const { expect, GET } = cds.test(__dirname + '/bookshop', '--profile', 'no-scheduling')
describe('SAP Passport', () => {
if (cds.env.requires.db.kind === 'sqlite') return test.skip('n/a for SQLite', () => {})
const admin = { auth: { username: 'alice' } }
cds.on('connect', async service => {
if (service.kind === 'hana') {
const { acquire } = service
service.acquire = async function () {
const dbc = await acquire.apply(this, arguments)
if (!dbc._native.set._patched) {
const { set } = dbc._native
dbc._native.set = function (obj) {
if ('SAP_PASSPORT' in obj) {
_passports.push(obj.SAP_PASSPORT)
_count++
}
return set.apply(this, arguments)
}
dbc._native.set._patched = true
}
return dbc
}
}
})
let _passports, _count
beforeEach(() => {
_passports = []
_count = 0
})
test('gets set once for simple queries', async () => {
const { status } = await GET('/odata/v4/admin/Books?$select=ID,title', admin)
expect(status).to.equal(200)
expect(_count).to.equal(2)
expect(_passports[0]).to.equal('') //> the reset
expect(_passports[1]).to.match(/^2A54482A/)
})
test('gets set twice for prepared statements', async () => {
const { status } = await GET("/odata/v4/admin/Books?$select=ID,title&$filter=title eq 'hurz'", admin)
expect(status).to.equal(200)
expect(_count).to.equal(3)
expect(_passports[0]).to.equal('') //> the reset
expect(_passports[1]).to.match(/^2A54482A/)
expect(_passports[2]).to.match(/^2A54482A/)
expect(_passports[1]).to.not.equal(_passports[2]) //> different for prepare and execute
})
})