Skip to content

Commit f0d7b57

Browse files
authored
description OR genre -> description AND genre (#41)
remove just.for.showcasing.attributeNesting attribute
1 parent aed19de commit f0d7b57

File tree

6 files changed

+36
-49
lines changed

6 files changed

+36
-49
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
POLICY "Reader" {
2-
ASSIGN ROLE "Reader" WHERE (description IS NOT RESTRICTED OR genre IS NOT RESTRICTED) AND stock IS NOT RESTRICTED;
2+
ASSIGN ROLE "Reader" WHERE
3+
genre IS NOT RESTRICTED AND
4+
description IS NOT RESTRICTED AND
5+
stock IS NOT RESTRICTED;
36
}
47

58
POLICY Inquisitor {
6-
ASSIGN ROLE "Inquisitor" WHERE description IS NOT RESTRICTED;
9+
ASSIGN ROLE "Inquisitor" WHERE
10+
description IS NOT RESTRICTED;
711
}
812

913
POLICY "admin" {

ams-cap-nodejs-bookshop/ams/dcl/internal/apiPolicies.dcl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@ INTERNAL Policy AMS_ValueHelp {
33
}
44

55
INTERNAL Policy ReadCatalog {
6-
USE cap.Reader RESTRICT stock < 30, description IS NOT RESTRICTED, genre IS NOT RESTRICTED;
6+
USE cap.Reader RESTRICT
7+
genre IS NOT RESTRICTED,
8+
description IS NOT RESTRICTED,
9+
stock < 30;
710
}
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
POLICY JuniorReader {
2-
USE cap.Reader RESTRICT description LIKE '%happy%ending%', genre IN ('Fantasy', 'Fairy Tale'),
3-
stock IS NOT RESTRICTED;
2+
USE cap.Reader RESTRICT
3+
genre IN ('Fantasy', 'Fairy Tale', 'Mystery'),
4+
description IS NOT RESTRICTED,
5+
stock IS NOT RESTRICTED;
46
}
57

68
POLICY BestsellerReader {
7-
USE cap.Reader RESTRICT stock < 20,
8-
description IS NOT RESTRICTED, genre IS NOT RESTRICTED;
9+
USE cap.Reader RESTRICT
10+
genre IS NOT RESTRICTED,
11+
description IS NOT RESTRICTED,
12+
stock < 20;
913
}
1014

1115
POLICY Zealot {
12-
USE cap.Inquisitor RESTRICT description LIKE '%religious%references%';
16+
USE cap.Inquisitor RESTRICT
17+
description LIKE '%religious%references%';
1318
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
// ---------------------------------HEADER_START-----------------------------------------------
2-
// Generated from a CAP model by the SAP AMS Plugin (@sap/ams) 2.0.0
3-
// hash of generated content: 8537b8096e1fb048199d1f1559d5eefc36a8df54921c560050a413d40c07688b
2+
// Generated from a CAP model by the SAP AMS Plugin (@sap/ams) 3.3.0
3+
// hash of generated content: 760f88aa8521b7b516c368a517af58f0a55f37dfd0be60eb07c5d94cc2ea3efe
44
// ----------------------------------HEADER_END------------------------------------------------
55

66
SCHEMA {
7-
description: String,
87
@valueHelp: {
98
path: 'Genres',
109
valueField: 'name',
1110
labelField: 'name'
1211
}
1312
genre: String,
14-
just: {
15-
for: {
16-
showcasing: {
17-
attributeNesting: Number
18-
}
19-
}
20-
},
13+
description: String,
2114
stock: Number
2215
}
Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
using { sap.capire.bookshop as my } from '../db/schema';
22
service AdminService @(requires:'admin', path: '/admin') {
33
entity Books as projection on my.Books;
4-
@ams.attributes: {
5-
just: {
6-
for: {
7-
showcasing: {
8-
attributeNesting: (ID)
9-
}
10-
}
11-
}
12-
}
134
entity Authors as projection on my.Authors;
145
}

ams-cap-nodejs-bookshop/test/cat-service.test.js

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,17 @@ describe('CatalogService', () => {
8585
})
8686

8787
/**
88-
* The JuniorReader policy adds attribute filters with an OR condition to the query:
89-
* - access to Eleonora is granted as its description hints at a happy ending
88+
* The JuniorReader policy adds attribute filters for genre to the query:
9089
* - access to Catweazle is granted as its genre is Fantasy
90+
* - access to The Raven, Eleonora is granted as their genre is Mystery
9191
*/
92-
it('/Books should return 2 Books (Eleonora, Catweazle)', async () => {
92+
it('/Books should return 3 Books (Catweazle, The Raven, Eleonora)', async () => {
9393
const { status, data } = await GET`/odata/v4/catalog/Books`
9494
expect(status).toBe(200)
95-
expect(data.value?.length).toBe(2)
96-
expect(data.value).toContainEqual(expect.objectContaining({ title: 'Eleonora' }))
97-
expect(data.value).toContainEqual(expect.objectContaining({ title: 'Catweazle' }))
98-
})
99-
100-
/**
101-
* On /ListOfBooks, the AMS description attribute is not mapped to a cds element, so access to Eleonora is forbidden
102-
*/
103-
it('/ListOfBooks should return 1 Book (Catweazle)', async () => {
104-
const { status, data } = await GET`/odata/v4/catalog/ListOfBooks`
105-
expect(status).toBe(200)
106-
expect(data.value?.length).toBe(1)
95+
expect(data.value?.length).toBe(3)
10796
expect(data.value).toContainEqual(expect.objectContaining({ title: 'Catweazle' }))
97+
expect(data.value).toContainEqual(expect.objectContaining({ title: 'The Raven' }))
98+
expect(data.value).toContainEqual(expect.objectContaining({ title: 'Eleonora' }))
10899
})
109100

110101
// Book 201 = Wuthering Heights
@@ -115,11 +106,11 @@ describe('CatalogService', () => {
115106
})
116107
})
117108

118-
// Book 252 = Eleonora
119-
it('/Books/252/getStockedValue() should return 7770', async () => {
120-
const { status, data } = await GET`/odata/v4/catalog/Books/252/getStockedValue()`
109+
// Book 271 = Catweazle
110+
it('/Books/271/getStockedValue() should return 3300', async () => {
111+
const { status, data } = await GET`/odata/v4/catalog/Books/271/getStockedValue()`
121112
expect(status).toBe(200)
122-
expect(data.value).toBe(7770)
113+
expect(data.value).toBe(3300)
123114
})
124115

125116
// 15711.35 = stocked value over ALL books because instance-based filters are NOT supported by CAP for functions bound to more than one entity
@@ -196,7 +187,7 @@ describe('CatalogService', () => {
196187
/**
197188
* The ReadCatalog API policy grants access to books with stock < 30
198189
*/
199-
it('/Books should return 2 Books (Eleonora, Catweazle)', async () => {
190+
it('/Books should return 3 Books with stock < 30 (Catweazle, Wuthering Heights, Jane Eyre)', async () => {
200191
const { status, data } = await GET`/odata/v4/catalog/Books`
201192
expect(status).toBe(200)
202193
expect(data.value?.length).toBe(3)
@@ -227,9 +218,9 @@ describe('CatalogService', () => {
227218
})
228219

229220
/**
230-
* The JuniorReader policy adds attribute filters with an OR condition to the query:
221+
* The JuniorReader policy adds attribute filters for genre to the query:
231222
* - access to Catweazle is granted as its genre is Fantasy
232-
* - access to Eleonora is granted as its description hints at a happy ending but filtered out by stock < 30 from ReadCatalog policy
223+
* - access to The Raven and Eleonora is granted as their genre is Mystery but filtered out by stock < 30 from ReadCatalog policy
233224
*/
234225
it('/Books should return 1 Book (Catweazle)', async () => {
235226
const { status, data } = await GET`/odata/v4/catalog/Books`

0 commit comments

Comments
 (0)