Skip to content

Commit

Permalink
fix: localization on hana (#354)
Browse files Browse the repository at this point in the history
for compat with current compiler, we need to set LOCALE and
APPLICATIONUSER
  • Loading branch information
johannes-vogel authored Nov 28, 2023
1 parent ff758ae commit 6aedb7d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
2 changes: 2 additions & 0 deletions hana/lib/HANAService.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class HANAService extends SQLService {
// REVISIT: required to be compatible with generated views
if (variables['$valid.from']) variables['VALID-FROM'] = variables['$valid.from']
if (variables['$valid.to']) variables['VALID-TO'] = variables['$valid.to']
if (variables['$user.id']) variables['APPLICATIONUSER'] = variables['$user.id']
if (variables['$user.locale']) variables['LOCALE'] = variables['$user.locale']

this.dbc.set(variables)
}
Expand Down
1 change: 1 addition & 0 deletions test/scenarios/bookshop/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ require('./delete.test')
require('./update.test')
require('./funcs.test')
require('./genres.test')
require('./localization.test')
29 changes: 29 additions & 0 deletions test/scenarios/bookshop/localization.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const cds = require('../../cds.js')
const bookshop = cds.utils.path.resolve(__dirname, '../../bookshop')

describe('Bookshop - localization', () => {
const { expect } = cds.test(bookshop)

test('expand texts', async () => {
const result = await cds.db.read('AdminService.Books', {ID: 201}).columns(c => { c.ID, c.title, c.texts(t => {t.locale, t.title})})
expect(result.texts).to.deep.include({locale: 'de', title: 'Sturmhöhe'})
})

test('locale from context/default', async () => {
const default_ = await SELECT.localized.from('AdminService.Books', {ID: 201}).columns('ID', 'title')
expect(default_.title).to.be.eq('Wuthering Heights')

await cds.tx({ locale: 'de' }, async (tx) => {
const de = await tx.run(SELECT.localized.from('AdminService.Books', {ID: 201}).columns('ID', 'title'))
expect(de.title).to.be.eq('Sturmhöhe')
})
})

test('insert texts', async () => {
await cds.insert({ ID: 201, locale: 'es', title: 'Cumbres borrascosas'}).into`AdminService.Books[ID=201].texts`
await cds.tx({ locale: 'es' }, async (tx) => {
const es = await tx.run(SELECT.localized.from('AdminService.Books', {ID: 201}).columns('ID', 'title'))
expect(es.title).to.be.eq('Cumbres borrascosas')
})
})
})

0 comments on commit 6aedb7d

Please sign in to comment.