diff --git a/ams-cap-nodejs-bookshop/.cdsrc.json b/ams-cap-nodejs-bookshop/.cdsrc.json index b26b848..8e1a7f8 100644 --- a/ams-cap-nodejs-bookshop/.cdsrc.json +++ b/ams-cap-nodejs-bookshop/.cdsrc.json @@ -46,11 +46,25 @@ "ias_apis": [ "ReadCatalog" ] + }, + "amsValueHelp": { + "policies": [ + "cap.admin" + ], + "ias_apis": [ + "AMS_ValueHelp" + ] } } }, "[production]": { "kind": "ias", + "config": { + "validation": { + "x5t": { "enabled": true }, + "proofToken": { "enabled": true } + } + }, "ams": { "cache": { "TTL": 15000 diff --git a/ams-cap-nodejs-bookshop/.gitignore b/ams-cap-nodejs-bookshop/.gitignore index e9844dd..42f4916 100644 --- a/ams-cap-nodejs-bookshop/.gitignore +++ b/ams-cap-nodejs-bookshop/.gitignore @@ -21,6 +21,7 @@ mta_archives/ .DS_Store *.orig *.log +Makefile_* *.iml *.flattened-pom.xml diff --git a/ams-cap-nodejs-bookshop/README.md b/ams-cap-nodejs-bookshop/README.md index cde3dd9..6a49311 100644 --- a/ams-cap-nodejs-bookshop/README.md +++ b/ams-cap-nodejs-bookshop/README.md @@ -80,6 +80,22 @@ To deploy with *sqlite*, you must copy the [db.sqlite](db.sqlite) file to `gen/s Please note that `cds add mta` creates a `mta.yaml` that contains a `before-all` command that runs `cds build --production`. This deletes and re-creates the `gen` folder after you manually copied the file. In that case, you should add another command behind it such as `cp db.sqlite gen/srv/db.sqlite` instead of manually copying. +### (Optional) Configure Value Help in mta.yaml +To add value help to your application, include provided-apis, value-help-url and value-help-api-name in ams-cap-nodejs-bookshop-auth: +```yaml + provided-apis: + - name: AMS_ValueHelp + description: Value Help Callback from AMS + type: public + authorization: + enabled: true + value-help-url: ~{srv-api/srv-cert-url}/odata/v4/ams-value-help/ + value-help-api-name: AMS_ValueHelp +requires: + - name: srv-api + - name: app-api +``` + ### Deployment :warning: Please make sure to use `@sap/cds-dk` version `>= 8.7.3` to get correct deployment configurations for *ams*/*ias*. Remember to update your global npm installation of `@sap/cds-dk` if you have one as it has priority over the version specified in *node_modules*. Use `cds version -i` to check. diff --git a/ams-cap-nodejs-bookshop/ams/dcl/schema.dcl b/ams-cap-nodejs-bookshop/ams/dcl/schema.dcl index 4810f25..a8ff9b4 100644 --- a/ams-cap-nodejs-bookshop/ams/dcl/schema.dcl +++ b/ams-cap-nodejs-bookshop/ams/dcl/schema.dcl @@ -5,6 +5,11 @@ SCHEMA { description: String, + @valueHelp: { + path: 'Genres', + valueField: 'name', + labelField: 'name' + } genre: String, just: { for: { diff --git a/ams-cap-nodejs-bookshop/db.sqlite b/ams-cap-nodejs-bookshop/db.sqlite index 53ceca7..e7a3835 100644 Binary files a/ams-cap-nodejs-bookshop/db.sqlite and b/ams-cap-nodejs-bookshop/db.sqlite differ diff --git a/ams-cap-nodejs-bookshop/srv/vh-service.cds b/ams-cap-nodejs-bookshop/srv/vh-service.cds new file mode 100644 index 0000000..ba4db76 --- /dev/null +++ b/ams-cap-nodejs-bookshop/srv/vh-service.cds @@ -0,0 +1,6 @@ +using { sap.capire.bookshop as my } from '../db/schema'; + +service AmsValueHelpService @(requires: 'admin') { + @cds.localized: false + entity Genres as projection on my.Genres; +} \ No newline at end of file diff --git a/ams-cap-nodejs-bookshop/test/vh-service.test.js b/ams-cap-nodejs-bookshop/test/vh-service.test.js new file mode 100644 index 0000000..494d883 --- /dev/null +++ b/ams-cap-nodejs-bookshop/test/vh-service.test.js @@ -0,0 +1,31 @@ +const cds = require('@sap/cds') + +describe('AmsValueHelpService', () => { + const { GET, axios } = cds.test() + + describe('called by fred (no admin)', () => { + beforeAll(() => { + axios.defaults.auth = { username: 'fred', password: '' } + }) + + it('/Genres should return status 403', async () => { + expect.assertions(1); + return (GET`/odata/v4/ams-value-help/Genres`).catch(error => { + expect(error.response.status).toBe(403) + }) + }) + }) + + describe('called by amsValueHelp (admin)', () => { + beforeAll(() => { + axios.defaults.auth = { username: 'amsValueHelp', password: '' } + }) + + it('/Genres should return all Genres', async () => { + const { status, data } = await GET`/odata/v4/ams-value-help/Genres` + expect(status).toBe(200) + expect(data.value?.length).toBe(15) + }) + }) + +})