Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ams-cap-nodejs-bookshop/.cdsrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ams-cap-nodejs-bookshop/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mta_archives/
.DS_Store
*.orig
*.log
Makefile_*

*.iml
*.flattened-pom.xml
Expand Down
16 changes: 16 additions & 0 deletions ams-cap-nodejs-bookshop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions ams-cap-nodejs-bookshop/ams/dcl/schema.dcl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

SCHEMA {
description: String,
@valueHelp: {
path: 'Genres',
valueField: 'name',
labelField: 'name'
}
genre: String,
just: {
for: {
Expand Down
Binary file modified ams-cap-nodejs-bookshop/db.sqlite
Binary file not shown.
6 changes: 6 additions & 0 deletions ams-cap-nodejs-bookshop/srv/vh-service.cds
Original file line number Diff line number Diff line change
@@ -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;
}
31 changes: 31 additions & 0 deletions ams-cap-nodejs-bookshop/test/vh-service.test.js
Original file line number Diff line number Diff line change
@@ -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)
})
})

})