Skip to content
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@sap/cds": ">=7"
},
"devDependencies": {
"@cap-js/sqlite": "^1",
"@cap-js/event-broker": "file:.",
"@sap-cloud-sdk/resilience": "^4.0.0",
"@sap/xssec": "^4.2.4"
Expand Down
3 changes: 3 additions & 0 deletions test/bookshop/db/data/my.bookshop-Books.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ID,title,stock
1,Wuthering Heights,100
2,Jane Eyre,500
2 changes: 2 additions & 0 deletions test/bookshop/db/data/my.bookshop-Customers.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ID,name,BusinessPartner,synchronized
1,John Doe,JD,true
14 changes: 14 additions & 0 deletions test/bookshop/db/schema.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace my.bookshop;

entity Books {
key ID : Integer;
title : String;
stock : Integer;
}

entity Customers {
key ID : Integer;
name : String;
BusinessPartner : String;
@readonly synchronized : Boolean;
}
37 changes: 37 additions & 0 deletions test/bookshop/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "bookshop",
"version": "1.0.0",
"description": "A simple CAP project.",
"repository": "<Add your repository here>",
"license": "UNLICENSED",
"private": true,
"dependencies": {
"@sap/cds": "^8",
"express": "^4",
"@cap-js/event-broker": "*",
"@cap-js/sqlite": "^1"
},
"scripts": {
"start": "cds-serve"
},
"cds": {
"requires": {
"auth": "mocked",
"db": {
"kind": "sqlite",
"credentials": {
"url": "sqlite.db",
"[development]": {
"url": ":memory:"
}
}
},
"messaging": {
"kind": "event-broker",
"[development]": {
"kind": "local-messaging"
}
}
}
}
}
5 changes: 5 additions & 0 deletions test/bookshop/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const cds = require('@sap/cds')

cds.on('served', async () => {
if (cds.env.requires.messaging.kind === 'event-broker') await cds.connect.to('ucl')
})
Binary file added test/bookshop/sqlite.db
Binary file not shown.
5 changes: 5 additions & 0 deletions test/bookshop/srv/cat-service.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using my.bookshop as my from '../db/schema';

service CatalogService {
@readonly entity Books as projection on my.Books;
}
10 changes: 10 additions & 0 deletions test/bookshop/srv/customers-service.cds
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using my.bookshop as my from '../db/schema';

@requires: 'admin'
service CustomersService {
entity Customers as projection on my.Customers;

event Customer.Changed @(topic: 'sap.s4.beh.businesspartner.v1.BusinessPartner.Changed.v1') {
BusinessPartner : String
}
}
23 changes: 23 additions & 0 deletions test/bookshop/srv/customers-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const cds = require('@sap/cds')

module.exports = class CustomersService extends cds.ApplicationService {
async init() {
const messaging = await cds.connect.to('messaging')

messaging.on('Customer.Changed', async function (msg) {
const { BusinessPartner } = msg.data
await UPDATE('my.bookshop.Customers').set({ synchronized: true }).where({ BusinessPartner })
})

this.before('UPDATE', 'Customers', function (req) {
req.data.synchronized = false
})

this.after('UPDATE', 'Customers', async function (data, req) {
const { BusinessPartner } = await SELECT.one.from(req.subject)
await messaging.emit('Customer.Changed', { BusinessPartner })
})

return super.init()
}
}
12 changes: 12 additions & 0 deletions test/bookshop/test.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
GET http://localhost:4004/odata/v4/customers/Customers(1)
Authorization: Basic alice:wonderland

###

PATCH http://localhost:4004/odata/v4/customers/Customers(1)
Authorization: Basic alice:wonderland
Content-Type: application/json

{
"name": "Jane Doe"
}