Bookshop showing user info

Show current user name, locale and tenant (if available).
Useful in deployments w/ real auth and tenant contexts.
This commit is contained in:
Christian Georgi
2022-03-28 13:54:16 +02:00
committed by Christian Georgi
parent 5fc86d45ad
commit bb55c432c9
5 changed files with 68 additions and 6 deletions

View File

@@ -1,7 +1,6 @@
const cds = require('@sap/cds/lib')
const { GET, expect } = cds.test ('@capire/bookshop')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
const { GET, expect, axios } = cds.test ('@capire/bookshop')
axios.defaults.auth = { username: 'alice', password: 'admin' }
describe('OData Protocol', () => {
@@ -76,3 +75,18 @@ describe('OData Protocol', () => {
])
})
})
describe('Misc', () => {
it('serves user info', async () => {
{
const { data } = await GET (`/user/Me`)
expect(data).to.containSubset({ ID: 'alice', locale:'en', tenant: null })
}
{
const { data } = await GET (`/user/Me`, {auth: { username: 'joe' }})
expect(data).to.containSubset({ ID: 'joe', locale:'en', tenant: null })
}
})
})