Skip to content

Commit 7b648ba

Browse files
Value Help for Nodejs bookshop sample (#19)
Value Help Service and corresponding test added to the sample, changes that need to be made in the mta.yaml are described in Readme
1 parent 84e5739 commit 7b648ba

File tree

7 files changed

+73
-0
lines changed

7 files changed

+73
-0
lines changed

ams-cap-nodejs-bookshop/.cdsrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,25 @@
4646
"ias_apis": [
4747
"ReadCatalog"
4848
]
49+
},
50+
"amsValueHelp": {
51+
"policies": [
52+
"cap.admin"
53+
],
54+
"ias_apis": [
55+
"AMS_ValueHelp"
56+
]
4957
}
5058
}
5159
},
5260
"[production]": {
5361
"kind": "ias",
62+
"config": {
63+
"validation": {
64+
"x5t": { "enabled": true },
65+
"proofToken": { "enabled": true }
66+
}
67+
},
5468
"ams": {
5569
"cache": {
5670
"TTL": 15000

ams-cap-nodejs-bookshop/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mta_archives/
2121
.DS_Store
2222
*.orig
2323
*.log
24+
Makefile_*
2425

2526
*.iml
2627
*.flattened-pom.xml

ams-cap-nodejs-bookshop/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ To deploy with *sqlite*, you must copy the [db.sqlite](db.sqlite) file to `gen/s
8080

8181
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.
8282

83+
### (Optional) Configure Value Help in mta.yaml
84+
To add value help to your application, include provided-apis, value-help-url and value-help-api-name in ams-cap-nodejs-bookshop-auth:
85+
```yaml
86+
provided-apis:
87+
- name: AMS_ValueHelp
88+
description: Value Help Callback from AMS
89+
type: public
90+
authorization:
91+
enabled: true
92+
value-help-url: ~{srv-api/srv-cert-url}/odata/v4/ams-value-help/
93+
value-help-api-name: AMS_ValueHelp
94+
requires:
95+
- name: srv-api
96+
- name: app-api
97+
```
98+
8399
### Deployment
84100
85101
: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.

ams-cap-nodejs-bookshop/ams/dcl/schema.dcl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
SCHEMA {
77
description: String,
8+
@valueHelp: {
9+
path: 'Genres',
10+
valueField: 'name',
11+
labelField: 'name'
12+
}
813
genre: String,
914
just: {
1015
for: {

ams-cap-nodejs-bookshop/db.sqlite

0 Bytes
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
using { sap.capire.bookshop as my } from '../db/schema';
2+
3+
service AmsValueHelpService @(requires: 'admin') {
4+
@cds.localized: false
5+
entity Genres as projection on my.Genres;
6+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const cds = require('@sap/cds')
2+
3+
describe('AmsValueHelpService', () => {
4+
const { GET, axios } = cds.test()
5+
6+
describe('called by fred (no admin)', () => {
7+
beforeAll(() => {
8+
axios.defaults.auth = { username: 'fred', password: '' }
9+
})
10+
11+
it('/Genres should return status 403', async () => {
12+
expect.assertions(1);
13+
return (GET`/odata/v4/ams-value-help/Genres`).catch(error => {
14+
expect(error.response.status).toBe(403)
15+
})
16+
})
17+
})
18+
19+
describe('called by amsValueHelp (admin)', () => {
20+
beforeAll(() => {
21+
axios.defaults.auth = { username: 'amsValueHelp', password: '' }
22+
})
23+
24+
it('/Genres should return all Genres', async () => {
25+
const { status, data } = await GET`/odata/v4/ams-value-help/Genres`
26+
expect(status).toBe(200)
27+
expect(data.value?.length).toBe(15)
28+
})
29+
})
30+
31+
})

0 commit comments

Comments
 (0)