Compare commits

..

1 Commits

Author SHA1 Message Date
Daniel
2ddaf45c5f OData Containment switched on 2020-11-20 19:04:33 +01:00
30 changed files with 72 additions and 134 deletions

View File

@@ -21,7 +21,6 @@
}, },
"rules": { "rules": {
"no-console": "off", "no-console": "off",
"require-atomic-updates": "off", "require-atomic-updates": "off"
"require-await":"warn"
} }
} }

View File

@@ -5,15 +5,12 @@ Find here a collection of samples for the [SAP Cloud Application Programming Mod
![](https://github.com/SAP-samples/cloud-cap-samples/workflows/CI/badge.svg) ![](https://github.com/SAP-samples/cloud-cap-samples/workflows/CI/badge.svg)
[![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/cloud-cap-samples)](https://api.reuse.software/info/github.com/SAP-samples/cloud-cap-samples) [![REUSE status](https://api.reuse.software/badge/github.com/SAP-samples/cloud-cap-samples)](https://api.reuse.software/info/github.com/SAP-samples/cloud-cap-samples)
### Preliminaries ### Preliminaries
1. [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) globally as documented in [capire](https://cap.cloud.sap) 1. [Install @sap/cds-dk](https://cap.cloud.sap/docs/get-started/) as documented in [capire](https://cap.cloud.sap)
```sh
npm i -g @sap/cds-dk
```
2. _Optional:_ [Use Visual Studio Code](https://cap.cloud.sap/docs/get-started/in-vscode) 2. _Optional:_ [Use Visual Studio Code](https://cap.cloud.sap/docs/get-started/in-vscode)
### Download ### Download
Clone this repo as shown below, if you have [git](https://git-scm.com/downloads) installed, Clone this repo as shown below, if you have [git](https://git-scm.com/downloads) installed,
@@ -42,8 +39,6 @@ cds watch bookshop
After that open this link in your browser: [http://localhost:4004](http://localhost:4004) After that open this link in your browser: [http://localhost:4004](http://localhost:4004)
When asked to log in, type `alice` as user and leave the password field blank, which is the [default user](https://cap.cloud.sap/docs/node.js/authentication#mocked).
### Testing ### Testing
Run the provided tests with [_jest_](http://jestjs.io) or [_mocha_](http://mochajs.org), for example: Run the provided tests with [_jest_](http://jestjs.io) or [_mocha_](http://mochajs.org), for example:
@@ -53,15 +48,15 @@ npx jest
> While mocha is a bit smaller and faster, jest runs tests in parallel and isolation, which allows to run all tests. > While mocha is a bit smaller and faster, jest runs tests in parallel and isolation, which allows to run all tests.
### Serve `npm` ### Serve `npm`
We've included a simple npm registry mock which allows you to do an `npm install @capire/<package>` locally. Use it as follows: We've simple npm registry mock included which allows you to do an `npm install @capire/<package>` anywhere locally. Use it as follows:
1. Start the @capire registry: 1. Start the @capire registry:
```sh ```sh
npm run registry npm run registry
``` ```
> While running this will have `@capire:registry=http://localhost:4444` set with npmrc. > While running this will have `@capire:registry=http://localhost:4444` set with npmrc.
2. Install one of the @capire packages wherever you like, e.g.: 2. Install one of the @capire packages wherever you like, e.g.:
```sh ```sh

0
bookshop/sqlite.db Normal file
View File

View File

@@ -1,12 +1,12 @@
using { sap.capire.bookshop as my } from '../db/schema'; using { sap.capire.bookshop as my } from '../db/schema';
service CatalogService @(path:'/browse') { service CatalogService @(path:'/browse') {
@readonly entity Books as SELECT from my.Books { *, @readonly entity Books as SELECT from my.Books {*,
author.name as author author.name as author
} excluding { createdBy, modifiedBy }; } excluding { createdBy, modifiedBy };
@readonly entity ListOfBooks as SELECT from Books @readonly entity ListOfBooks as SELECT from Books
excluding { descr }; excluding { descr, stock };
@requires: 'authenticated-user' @requires: 'authenticated-user'
action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer }; action submitOrder ( book: Books:ID, amount: Integer ) returns { stock: Integer };

View File

@@ -1,7 +1,7 @@
const cds = require('@sap/cds') const cds = require('@sap/cds')
const { Books } = cds.entities ('sap.capire.bookshop') const { Books } = cds.entities ('sap.capire.bookshop')
class CatalogService extends cds.ApplicationService { init(){ class CatalogService extends cds.ApplicationService { async init(){
// Reduce stock of ordered books if available stock suffices // Reduce stock of ordered books if available stock suffices
this.on ('submitOrder', async req => { this.on ('submitOrder', async req => {
@@ -9,7 +9,7 @@ class CatalogService extends cds.ApplicationService { init(){
let {stock} = await tx.read('stock').from(Books,book) let {stock} = await tx.read('stock').from(Books,book)
if (stock >= amount) { if (stock >= amount) {
await tx.update (Books,book).with ({ stock: stock -= amount }) await tx.update (Books,book).with ({ stock: stock -= amount })
await this.emit ('OrderedBook', { book, amount, buyer:req.user.id }) this.emit ('OrderedBook', { book, amount, buyer:req.user.id })
return { stock } return { stock }
} }
else return req.error (409,`${amount} exceeds stock for book #${book}`) else return req.error (409,`${amount} exceeds stock for book #${book}`)

View File

@@ -1,8 +1,4 @@
{ {
"name": "@capire/common", "name": "@capire/common",
"description": "Provides a pre-built extension package for std @sap/cds/common", "version": "1.0.0"
"version": "1.0.0",
"dependencies": {
"@sap/cds": "latest"
}
} }

View File

@@ -1 +0,0 @@
# this file is not used

View File

@@ -1,14 +0,0 @@
Books = Chinesische Bücher
Book = Chinesiches Buch
ID = CN ID
Title = Chinese Titel
Authors = Chinese Autoren
Author = Chinese Autor
AuthorID = Chinese ID des Autors
AuthorName = Chinese Name des Autors
Name = Chinese Name
Stock = Chinese Bestand
Order = Chinese Bestellung
Orders = Chinese Bestellungen
Price = Chinese Preis
Genre = Chinese Genre

View File

@@ -13,7 +13,7 @@
applications: { applications: {
"browse-books": { "browse-books": {
title: "Browse Books", title: "Browse Books",
description: "w/ SAP Fiori Elements", description: "... testing FE v42",
additionalInformation: "SAPUI5.Component=bookshop", additionalInformation: "SAPUI5.Component=bookshop",
applicationType : "URL", applicationType : "URL",
url: "/browse/webapp", url: "/browse/webapp",
@@ -21,7 +21,7 @@
}, },
"manage-books": { "manage-books": {
title: "Manage Books", title: "Manage Books",
description: "w/ SAP Fiori Elements", description: "... testing FE v42",
additionalInformation: "SAPUI5.Component=admin", additionalInformation: "SAPUI5.Component=admin",
applicationType : "URL", applicationType : "URL",
url: "/admin/webapp", url: "/admin/webapp",
@@ -29,7 +29,7 @@
}, },
"manage-orders": { "manage-orders": {
title: "Manage Orders", title: "Manage Orders",
description: "w/ SAP Fiori Elements", description: "... testing FE v42",
additionalInformation: "SAPUI5.Component=orders", additionalInformation: "SAPUI5.Component=orders",
applicationType : "URL", applicationType : "URL",
url: "/orders/webapp", url: "/orders/webapp",
@@ -40,7 +40,8 @@
</script> </script>
<script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script> <script id="sap-ushell-bootstrap" src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" <!-- <script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" -->
<script id="sap-ui-bootstrap" src="https://sapui5.hana.ondemand.com/1.78.6/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout" data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration, sap.ui.layout"
data-sap-ui-compatVersion="edge" data-sap-ui-compatVersion="edge"
data-sap-ui-theme="sap_fiori_3" data-sap-ui-theme="sap_fiori_3"

View File

@@ -7,8 +7,8 @@ using CatalogService from '@capire/bookshop';
annotate CatalogService.Books with @( annotate CatalogService.Books with @(
UI: { UI: {
HeaderInfo: { HeaderInfo: {
TypeName: '{i18n>Book}', TypeName: 'Book',
TypeNamePlural: '{i18n>Books}', TypeNamePlural: 'Books',
Description: {Value: author} Description: {Value: author}
}, },
HeaderFacets: [ HeaderFacets: [

View File

@@ -19,7 +19,7 @@ extend Books with {
// Extend Orders with Books as Products // Extend Orders with Books as Products
// //
using { sap.capire.orders.Orders_Items } from '@capire/orders'; using { sap.capire.orders.OrderItems } from '@capire/orders';
extend Orders_Items with { extend OrderItems with {
book : Association to Books on product.ID = book.ID book : Association to Books on product.ID = book.ID
} }

View File

@@ -49,7 +49,7 @@ module.exports = async()=>{ // called by server.js
// //
// Reduce stock of ordered books for orders are created from Orders admin UI // Reduce stock of ordered books for orders are created from Orders admin UI
// //
OrdersService.on ('OrderChanged', (msg) => { OrdersService.on ('OrderChanged', async (msg) => {
console.debug ('> received:', msg.event, msg.data) console.debug ('> received:', msg.event, msg.data)
const { product, deltaAmount } = msg.data const { product, deltaAmount } = msg.data
return UPDATE (Books) .where ('ID =', product) return UPDATE (Books) .where ('ID =', product)

View File

@@ -42,24 +42,7 @@ GET {{bookshop}}/browse/Books(201)?
################################################# #################################################
# #
# Orders Service, incl. draft choreography # Orders Service
# #
@newOrderID = e939604c-ab83-4d4f-bdb6-95fe30b3773e
GET {{bookshop}}/orders/Orders GET {{bookshop}}/orders/Orders
### Create order, still inactive
POST {{bookshop}}/orders/Orders
Content-Type: application/json
{"ID": "{{newOrderID}}"}
### Get inactive order. We have to specify `IsActiveEntity`.
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)
### Activate order using `.../<servicename>.draftActivate`
POST {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=false)/OrdersService.draftActivate
Content-Type: application/json
### Get active order
GET {{bookshop}}/orders/Orders(ID={{newOrderID}},IsActiveEntity=true)

View File

@@ -68,7 +68,7 @@ annotate OrdersService.Orders with @(
annotate OrdersService.Orders_Items with @( annotate OrdersService.OrderItems with @(
UI: { UI: {
LineItem: [ LineItem: [
{Value: product_ID, Label:'Product ID'}, {Value: product_ID, Label:'Product ID'},

View File

@@ -121,7 +121,7 @@
"name": "sap.fe.templates.ObjectPage", "name": "sap.fe.templates.ObjectPage",
"options": { "options": {
"settings" : { "settings" : {
"entitySet": "Orders_Items" "entitySet": "OrderItems"
} }
} }
}, },

View File

@@ -1,4 +1,4 @@
ID;up__ID;amount;product_ID;title;price ID;order_ID;amount;product_ID;title;price
58040e66-1dcd-4ffb-ab10-fdce32028b79;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;201;Wuthering Heights;11.11 58040e66-1dcd-4ffb-ab10-fdce32028b79;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;201;Wuthering Heights;11.11
64e718c9-ff99-47f1-8ca3-950c850777d4;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;271;Catweazle;15 64e718c9-ff99-47f1-8ca3-950c850777d4;7e2f2640-6866-4dcf-8f4d-3027aa831cad;1;271;Catweazle;15
e9641166-e050-4261-bfee-d1e797e6cb7f;64e718c9-ff99-47f1-8ca3-950c850777d4;2;252;Eleonora;28 e9641166-e050-4261-bfee-d1e797e6cb7f;64e718c9-ff99-47f1-8ca3-950c850777d4;2;252;Eleonora;28
1 ID up__ID order_ID amount product_ID title price
2 58040e66-1dcd-4ffb-ab10-fdce32028b79 7e2f2640-6866-4dcf-8f4d-3027aa831cad 7e2f2640-6866-4dcf-8f4d-3027aa831cad 1 201 Wuthering Heights 11.11
3 64e718c9-ff99-47f1-8ca3-950c850777d4 7e2f2640-6866-4dcf-8f4d-3027aa831cad 7e2f2640-6866-4dcf-8f4d-3027aa831cad 1 271 Catweazle 15
4 e9641166-e050-4261-bfee-d1e797e6cb7f 64e718c9-ff99-47f1-8ca3-950c850777d4 64e718c9-ff99-47f1-8ca3-950c850777d4 2 252 Eleonora 28

View File

@@ -1,26 +1,26 @@
using { Currency, User, managed, cuid } from '@sap/cds/common'; using { Currency, User, managed, cuid } from '@sap/cds/common';
using from '@capire/common';
namespace sap.capire.orders; namespace sap.capire.orders;
entity Orders : cuid, managed { entity Orders : cuid, managed {
OrderNo : String @title:'Order Number'; //> readable key OrderNo : String @title:'Order Number'; //> readable key
Items : Composition of many Orders_Items on Items.up_ = $self; Items : Composition of many OrderItems on Items.order = $self;
buyer : User; buyer : User;
currency : Currency; currency : Currency;
} }
entity Orders_Items { entity OrderItems {
key ID : UUID; key ID : UUID;
up_ : Association to Orders; order : Association to Orders;
product : Association to Products @assert.integrity:false; // REVISIT: this is a temporary workaround for a glitch in cds-runtime @assert.integrity:false // REVISIT: this is a temporary workaround for a glitch in cds-runtime
product : Association to Products;
amount : Integer; amount : Integer;
title : String; title : String;
price : Double; price : Double;
} }
/** This is a stand-in for arbitrary ordered Products */ /** This is a stand-in for arbitrary ordered Products */
entity Products @(cds.persistence.skip:'always') { @cds.persistence.skip:'always'
entity Products {
key ID : String; key ID : String;
} }
// Activate extension package
using from '@capire/common';

View File

@@ -4,5 +4,10 @@
"dependencies": { "dependencies": {
"@capire/common": "*", "@capire/common": "*",
"@sap/cds": "^4.3.0" "@sap/cds": "^4.3.0"
},
"cds": {
"odata": {
"containment": true
}
} }
} }

View File

@@ -3,24 +3,24 @@ class OrdersService extends cds.ApplicationService {
/** register custom handlers */ /** register custom handlers */
init(){ init(){
const { Orders_Items:OrderItems } = this.entities const { OrderItems } = this.entities
this.before ('UPDATE', 'Orders', async function(req) { this.before ('UPDATE', 'Orders', async function(req) {
const { ID, Items } = req.data const { ID, Items } = req.data
if (Items) for (let { product_ID, amount } of Items) { if (Items) for (let { product_ID, amount } of Items) {
const { amount:before } = await cds.tx(req).run ( const { amount:before } = await cds.tx(req).run (
SELECT.one.from (OrderItems, oi => oi.amount) .where ({up__ID:ID, product_ID}) SELECT.one.from (OrderItems, oi => oi.amount) .where ({order_ID:ID, product_ID})
) )
if (amount != before) await this.orderChanged (product_ID, amount-before) if (amount != before) this.orderChanged (product_ID, amount-before)
} }
}) })
this.before ('DELETE', 'Orders', async function(req) { this.before ('DELETE', 'Orders', async function(req) {
const { ID } = req.data const { ID } = req.data
const Items = await cds.tx(req).run ( const Items = await cds.tx(req).run (
SELECT.from (OrderItems, oi => { oi.product_ID, oi.amount }) .where ({up__ID:ID}) SELECT.from (OrderItems, oi => { oi.product_ID, oi.amount }) .where ({order_ID:ID})
) )
if (Items) await Promise.all (Items.map(it => this.orderChanged (it.product_ID, -it.amount))) if (Items) for (let it of Items) this.orderChanged (it.product_ID, -it.amount)
}) })
return super.init() return super.init()

View File

@@ -37,7 +37,7 @@ const reviews = new Vue ({
reviews.message = {} reviews.message = {}
}, },
newReview () { async newReview () {
reviews.review = {} reviews.review = {}
reviews.message = {} reviews.message = {}
setTimeout (()=> $('form > input').focus(), 111) setTimeout (()=> $('form > input').focus(), 111)

View File

@@ -1,5 +1,5 @@
const cds = require ('@sap/cds') const cds = require ('@sap/cds')
module.exports = cds.service.impl (function(){ module.exports = cds.service.impl (async function(){
// Get the CSN definition for Reviews from the db schema for sub-sequent queries // Get the CSN definition for Reviews from the db schema for sub-sequent queries
// ( Note: we explicitly specify the namespace to support embedded reuse ) // ( Note: we explicitly specify the namespace to support embedded reuse )
@@ -16,7 +16,7 @@ module.exports = cds.service.impl (function(){
SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject}) SELECT.one (['round(avg(rating),2) as rating']) .from (Reviews) .where ({subject})
) )
global.it || console.log ('< emitting:', 'reviewed', { subject, rating }) global.it || console.log ('< emitting:', 'reviewed', { subject, rating })
await this.emit ('reviewed', { subject, rating }) this.emit ('reviewed', { subject, rating })
}) })
// Increment counter for reviews considered helpful // Increment counter for reviews considered helpful

View File

@@ -1,5 +1,5 @@
const { expect } = require('../test')
const cds = require('@sap/cds/lib') const cds = require('@sap/cds/lib')
const { expect } = cds.test
const CQL = ([cql]) => cds.parse.cql(cql) const CQL = ([cql]) => cds.parse.cql(cql)
const Foo = { name: 'Foo' } const Foo = { name: 'Foo' }
const Books = { name: 'capire.bookshop.Books' } const Books = { name: 'capire.bookshop.Books' }
@@ -325,26 +325,7 @@ describe('cds.ql → cqn', () => {
}) })
// using CQL fragments -> uses cds.parse.expr // using CQL fragments -> uses cds.parse.expr
const is_v2 = !!cds.parse.expr('(1,2)').list expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
if (is_v2) expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['ID'] },
'=',
{ val: ID },
'and',
{ ref: ['x'] },
'in',
{list:[
{ ref: ['foo'] },
{ val: 'bar' },
{ val: 3 },
]}
],
},
})
else expect((cqn = CQL`SELECT from Foo where ID=11 and x in ( foo, 'bar', 3)`)).to.eql({
SELECT: { SELECT: {
from: { ref: ['Foo'] }, from: { ref: ['Foo'] },
where: [ where: [

View File

@@ -1,7 +1,7 @@
const { expect } = require('../test') .run (
'serve', 'AdminService', '--from', '@capire/bookshop,@capire/common', '--in-memory'
)
const cds = require('@sap/cds/lib') const cds = require('@sap/cds/lib')
const { expect } = cds.test (
'serve', 'AdminService', '--from', '@capire/bookshop,@capire/common', '--in-memory'
).in(__dirname)
describe('Consuming Services locally', () => { describe('Consuming Services locally', () => {
// //

View File

@@ -1,7 +1,5 @@
const { GET, POST, expect } = require('../test') .run ('bookshop') const cds = require('@sap/cds/lib'); cds.User = cds.User.Privileged // skip auth
const cds = require('@sap/cds/lib') const { GET, POST, expect } = cds.test('bookshop').in(__dirname,'..')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
describe('Custom Handlers', () => { describe('Custom Handlers', () => {

View File

@@ -1,4 +1,5 @@
const { GET, expect } = require('../test') .run ('serve','hello/world.cds') const cds = require('@sap/cds/lib')
const { GET, expect } = cds.test('serve','hello/world.cds').in(__dirname,'..')
describe('Hello world!', () => { describe('Hello world!', () => {

View File

@@ -1,5 +1,6 @@
const {expect} = require('../test') const cwd = process.cwd(); process.chdir (__dirname) //> only for internal CI/CD@SAP
const cds = require('@sap/cds/lib') const cds = require('@sap/cds/lib')
const {expect} = cds.test
// monkey patching older releases: // monkey patching older releases:
if (!cds.compile.cdl) cds.compile.cdl = cds.parse if (!cds.compile.cdl) cds.compile.cdl = cds.parse
@@ -24,6 +25,8 @@ describe('Hierarchical Data', ()=>{
expect (cds.db.model) .to.exist expect (cds.db.model) .to.exist
}) })
after(()=> process.chdir(cwd))
it ('supports deeply nested inserts', ()=> INSERT.into (Cats, it ('supports deeply nested inserts', ()=> INSERT.into (Cats,
{ ID:100, name:'Some Cats...', children:[ { ID:100, name:'Some Cats...', children:[
{ ID:101, name:'Cat', children:[ { ID:101, name:'Cat', children:[

View File

@@ -1,6 +0,0 @@
const test = require('@sap/cds/lib/utils/tests').in(__dirname,'..')
module.exports = Object.assign(test,{run:test})
// REVISIT: With upcoming release of @sap/cds this should become:
// module.exports = require('@sap/cds/tests').in(__dirname,'..')

View File

@@ -1,7 +1,5 @@
const { GET, expect } = require('../test') .run ('serve', 'test/localized-data.cds', '--in-memory') const cds = require('@sap/cds/lib'); cds.User = cds.User.Privileged // skip auth
const cds = require('@sap/cds/lib') const { GET, expect } = cds.test ('serve', __dirname+'/localized-data.cds', '--in-memory')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
describe('Localized Data', () => { describe('Localized Data', () => {

View File

@@ -1,11 +1,13 @@
const { expect } = require('../test')
const cds = require('@sap/cds/lib') const cds = require('@sap/cds/lib')
const cwd = process.cwd(); process.chdir (__dirname) //> only for internal CI/CD@SAP
const {expect} = cds.test
const _model = '@capire/reviews' const _model = '@capire/reviews'
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch cds.User = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
describe('Messaging', ()=>{ describe('Messaging', ()=>{
after(()=> process.chdir(cwd))
it ('should bootstrap sqlite in-memory db', async()=>{ it ('should bootstrap sqlite in-memory db', async()=>{
const db = await cds.deploy (_model) .to ('sqlite::memory:') const db = await cds.deploy (_model) .to ('sqlite::memory:')
await db.delete('Reviews') await db.delete('Reviews')
@@ -42,16 +44,16 @@ describe('Messaging', ()=>{
// { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }, // { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N },
// ), // ),
srv.create ('Reviews') .entries ( srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N } { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
), ),
srv.create ('Reviews') .entries ( srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N } { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
), ),
srv.create ('Reviews') .entries ( srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N } { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
), ),
srv.create ('Reviews') .entries ( srv.create ('Reviews') .entries (
{ ID: String(111 + (++N)), subject: "201", title: "Captivating", rating: N } { ID: 111 + (++N), subject: "201", title: "Captivating", rating: N }
), ),
])) ]))

View File

@@ -1,11 +1,8 @@
const { GET, expect } = require('../test') .run ('bookshop') const cds = require('@sap/cds/lib'); cds.User = cds.User.Privileged // skip auth
const cds = require('@sap/cds/lib') const { GET, expect } = cds.test('bookshop').in(__dirname,'..')
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
describe('OData Protocol', () => { describe('OData Protocol', () => {
it('serves $metadata documents in v4', async () => { it('serves $metadata documents in v4', async () => {
const { headers, status, data } = await GET `/browse/$metadata` const { headers, status, data } = await GET `/browse/$metadata`
expect(status).to.equal(200) expect(status).to.equal(200)