Compare commits
43 Commits
CAA265-nod
...
openSAP-we
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
810cac12d0 | ||
|
|
2cb2842dbe | ||
|
|
e467635696 | ||
|
|
a12cd7f4ec | ||
|
|
fa187be617 | ||
|
|
06755978b2 | ||
|
|
02469acebb | ||
|
|
e2b47228db | ||
|
|
13480ad99e | ||
|
|
8071faa62d | ||
|
|
9ea294586a | ||
|
|
a56a11ff3e | ||
|
|
b4084b45cb | ||
|
|
26e3c0d753 | ||
|
|
6d0194acc0 | ||
|
|
db75a99808 | ||
|
|
a04755efed | ||
|
|
6a9a1bc4d6 | ||
|
|
a0847e603f | ||
|
|
b1270bc0eb | ||
|
|
ba72d7f478 | ||
|
|
cd808c76dd | ||
|
|
3a77707f49 | ||
|
|
583c97a494 | ||
|
|
eb7431afed | ||
|
|
630bb2b19c | ||
|
|
f9a7aa59de | ||
|
|
c0bce5ae5b | ||
|
|
ad05e2b9db | ||
|
|
b7c2eee961 | ||
|
|
9205e0893a | ||
|
|
7137bf227e | ||
|
|
c2d0fba1d8 | ||
|
|
345d7fa37b | ||
|
|
88c1aa0282 | ||
|
|
c4cd02dbe9 | ||
|
|
b9269ad437 | ||
|
|
2783197f1c | ||
|
|
3238b8b045 | ||
|
|
dcac8fe7d2 | ||
|
|
cc3aca29ef | ||
|
|
baaa5ef7d7 | ||
|
|
e657683322 |
@@ -6,7 +6,7 @@
|
|||||||
"jest": true
|
"jest": true
|
||||||
},
|
},
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 2017
|
"ecmaVersion": 2018
|
||||||
},
|
},
|
||||||
"globals": {
|
"globals": {
|
||||||
"SELECT": true,
|
"SELECT": true,
|
||||||
|
|||||||
37
.vscode/launch.json
vendored
Normal file
37
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "bookshop", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
|
"args": [ "--", "cds", "run", "--in-memory" ],
|
||||||
|
"cwd": "${workspaceFolder}/packages/bookshop",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"skipFiles": ["<node_internals>/**"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cds run ...", "request": "launch", "type": "node", "runtimeExecutable": "npx", "runtimeArgs": [ "-n" ],
|
||||||
|
"args": [ "--", "cds", "run", "--with-mocks", "--in-memory?" ],
|
||||||
|
"cwd": "${workspaceFolder}/packages/${input:service}",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"skipFiles": ["<node_internals>/**"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"type": "pickString",
|
||||||
|
"id": "service",
|
||||||
|
"description": "Which service do you want to start?",
|
||||||
|
"options": [
|
||||||
|
"bookshop",
|
||||||
|
"bookstore",
|
||||||
|
"media-server",
|
||||||
|
"office-supplies",
|
||||||
|
"reviews-service"
|
||||||
|
],
|
||||||
|
"default": "bookshop"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"files.exclude": {
|
||||||
|
"**/.gitignore": true,
|
||||||
|
"**/.vscode": true
|
||||||
|
}
|
||||||
|
}
|
||||||
17
.vscode/tasks.json
vendored
Normal file
17
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||||
|
// for the documentation about the tasks.json format
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"type": "npm", "script": "watch", "path": "packages/bookshop/",
|
||||||
|
"options": { "env": { "PORT": "4004" }},
|
||||||
|
"presentation": { "group": "A" }
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "npm", "script": "watch", "path": "packages/reviews-service/",
|
||||||
|
"options": { "env": { "PORT": "5005" }},
|
||||||
|
"presentation": { "group": "A" }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
68
README.md
68
README.md
@@ -1,58 +1,42 @@
|
|||||||
# cloud-cap-samples
|
# Welcome to SAP Cloud Application Programming model samples
|
||||||
|
|
||||||
This is a monorepository for sample projects on [SAP Cloud Application Programming Model](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/00823f91779d4d42aa29a498e0535cdf.html?q=cloud%20application%20programming%20model).
|
Find here the samples for the openSAP course [Building Applications with the SAP Cloud Application Programming Model](https://open.sap.com/courses/cp7).
|
||||||
|
|
||||||
## Description
|
## Get Access to SAP Business Application Studio
|
||||||
|
The recommended environment for the course is SAP Business Application Studio. Watch [unit 2 of week 1](https://open.sap.com/courses/cp7/items/51pzQUzbXHr2kdbOmVs6jI) for how to get access.
|
||||||
|
|
||||||
This repository provides a list of samples and reusable packages created based on SAP Cloud Application Programming Model.
|
## Setup
|
||||||
The SAP Cloud Application Programming Model enables you to quickly create business applications by allowing you to focus on your domain logic. It offers a consistent end-to-end programming model that includes languages, libraries and APIs tailored for full-stack development on SAP Cloud Platform.
|
|
||||||
|
|
||||||
The samples provided can be run in a local setup on SQLite Database.
|
In SAP Business Application Studio, open a terminal.
|
||||||
|
Then clone the repo with this specific branch:
|
||||||
|
|
||||||
#### Samples:
|
```sh
|
||||||
* [bookstore](./packages/bookstore) - A variant of the bookshop application, built in a modular fashion on top of products-service and common reuse packages.
|
git clone https://github.com/sap-samples/cloud-cap-samples projects/cloud-cap-samples -b openSAP-week2-unit1
|
||||||
* [products-service](./packages/products-service) - A reuse package providing domain models and services to manage product catalogs.
|
cd projects/cloud-cap-samples
|
||||||
|
```
|
||||||
|
|
||||||
## Requirements
|
In the `cloud-cap-samples` folder run:
|
||||||
* [Node.js](https://nodejs.org/en/) v8 or higher
|
```sh
|
||||||
* [Git](https://git-scm.com)
|
npm install
|
||||||
* [SQLite DB](https://www.sqlite.org/download.html) (Windows only; pre-installed on Mac/Linux)
|
```
|
||||||
|
|
||||||
#### Optional (if you want to import the code into an editor)
|
## Run
|
||||||
* [VS Code](https://code.visualstudio.com)
|
|
||||||
* [Add CDS extension to VS](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/be944d6d51f343f6b3f53c29c44ff00a.html)
|
|
||||||
|
|
||||||
## Download and Installation
|
Now you're ready to run the samples, for example:
|
||||||
|
```sh
|
||||||
|
cd packages/bookshop
|
||||||
|
cds watch
|
||||||
|
```
|
||||||
|
|
||||||
#### Clone and build the application
|
After that, watch out for the little popup in the lower right corner of SAP Business Application Studio that asks you to open the application in your browser.
|
||||||
`git clone https://github.com/SAP-samples/cloud-cap-samples.git`
|
|
||||||
|
|
||||||
`cd samples`
|
|
||||||
|
|
||||||
`npm install`
|
|
||||||
|
|
||||||
#### Run the samples
|
|
||||||
|
|
||||||
`npm run <sample name>`
|
|
||||||
|
|
||||||
|
|
||||||
## Limitations
|
## Get Support
|
||||||
|
|
||||||
None
|
Check out the cap docs at https://cap.cloud.sap. <br>
|
||||||
|
In case you find a bug or need support, please [open an issue in here](https://github.com/SAP-samples/cloud-cap-samples/issues/new).
|
||||||
|
|
||||||
## Known Issues
|
|
||||||
|
|
||||||
None
|
|
||||||
|
|
||||||
## How to obtain support
|
|
||||||
|
|
||||||
In case you find a bug, or you need additional support, please open an issue [here](https://github.wdf.sap.corp/staging-for-SAP-samples-public/cloud-cap-samples/issues) in GitHub.
|
|
||||||
|
|
||||||
## To-Do (upcoming changes)
|
|
||||||
|
|
||||||
None
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright (c) 2019 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.
|
Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under SAP Sample Code License Agreement, except as noted otherwise in the [LICENSE](/LICENSE) file.
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1 @@
|
|||||||
{
|
{"packages":["packages/*"],"version":"1.0.0"}
|
||||||
"packages": [
|
|
||||||
"packages/*",
|
|
||||||
"shared/*"
|
|
||||||
],
|
|
||||||
"version": "0.0.0"
|
|
||||||
}
|
|
||||||
|
|||||||
2064
package-lock.json
generated
Normal file
2064
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
29
package.json
29
package.json
@@ -1,16 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "@sap/capire-samples",
|
"name": "@sap/capire-samples",
|
||||||
"description": "The umbrella project for all samples to easily setup for local development and tests.",
|
"description": "The umbrella project for all samples to easily setup for local development and tests.",
|
||||||
"repository": "https://github.wdf.sap.corp/capire/samples.git",
|
"repository": "https://github.com/SAP-samples/cloud-cap-samples.git",
|
||||||
"author": "daniel.hutzel@sap.com",
|
"author": "daniel.hutzel@sap.com",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"install": "(npx --no-install lerna -v || npm i lerna --no-save) && lerna bootstrap --hoist --ignore tests-env --loglevel warn",
|
"lerna": "npx --no-install lerna -v > /dev/null || npm i lerna --no-save",
|
||||||
"reset": "lerna clean -y && rm -fr node_modules",
|
"install": "(npm -s run lerna) && lerna bootstrap --hoist",
|
||||||
"test": "jest",
|
"cleanup": "lerna clean -y && rm -fr node_modules",
|
||||||
"bookstore": "cds run packages/bookstore --in-memory",
|
"bookshop": "cds watch packages/bookshop",
|
||||||
"products-service": "cds run packages/products-service --in-memory",
|
"bookshop-enhanced": "cds watch packages/bookshop-enhanced",
|
||||||
"reviews-service": "cds run packages/reviews-service --in-memory"
|
"reviews-service": "cds watch packages/reviews-service",
|
||||||
|
"bookstore": "cds watch packages/bookstore",
|
||||||
|
"media-server": "cds watch packages/media-server"
|
||||||
},
|
},
|
||||||
"license": "ISC"
|
"dependencies": {
|
||||||
|
"@sap/cds": "^3",
|
||||||
|
"express": "^4"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"sqlite3": "*"
|
||||||
|
},
|
||||||
|
"--add-these-to-devDependencies-for-tests": {
|
||||||
|
"@types/jest": "*",
|
||||||
|
"jest": "*"
|
||||||
|
},
|
||||||
|
"license": "SAP SAMPLE CODE LICENSE"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ID;name
|
||||||
|
101;Emily Brontë
|
||||||
|
107;Charlotte Brontë
|
||||||
|
150;Edgar Allen Poe
|
||||||
|
170;Richard Carpenter
|
||||||
|
6
packages/bookshop/db/data/sap.capire.bookshop-Books.csv
Normal file
6
packages/bookshop/db/data/sap.capire.bookshop-Books.csv
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
ID;title;author_ID;stock
|
||||||
|
201;Wuthering Heights;101;12
|
||||||
|
207;Jane Eyre;107;11
|
||||||
|
251;The Raven;150;333
|
||||||
|
252;Eleonora;150;555
|
||||||
|
271;Catweazle;170;22
|
||||||
|
40
packages/bookshop/db/schema.cds
Normal file
40
packages/bookshop/db/schema.cds
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
namespace sap.capire.bookshop;
|
||||||
|
using { Currency, managed } from '@sap/cds/common';
|
||||||
|
|
||||||
|
entity Books : managed, additionalInfo {
|
||||||
|
key ID : Integer;
|
||||||
|
title : localized String(111);
|
||||||
|
descr : localized String(1111);
|
||||||
|
author : Association to Authors;
|
||||||
|
stock : Integer;
|
||||||
|
price : Decimal(9,2);
|
||||||
|
currency : Currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Authors : managed {
|
||||||
|
key ID : Integer;
|
||||||
|
name : String(111);
|
||||||
|
books : Association to many Books on books.author = $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Orders : managed {
|
||||||
|
key ID : UUID;
|
||||||
|
OrderNo : String @title:'Order Number'; //> readable key
|
||||||
|
Items : Composition of many OrderItems on Items.parent = $self;
|
||||||
|
}
|
||||||
|
entity OrderItems {
|
||||||
|
key ID : UUID;
|
||||||
|
parent : Association to Orders;
|
||||||
|
book : Association to Books;
|
||||||
|
amount : Integer;
|
||||||
|
}
|
||||||
|
|
||||||
|
entity Movies: additionalInfo {
|
||||||
|
key ID : Integer;
|
||||||
|
name : String(111);
|
||||||
|
}
|
||||||
|
|
||||||
|
aspect additionalInfo{
|
||||||
|
genre: String(100);
|
||||||
|
language: String(200);
|
||||||
|
}
|
||||||
14
packages/bookshop/package.json
Normal file
14
packages/bookshop/package.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "bookshop",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "A simple CAP project.",
|
||||||
|
"repository": "<Add your repository here>",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"@sap/cds": "^3",
|
||||||
|
"express": "^4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "npx cds run"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
packages/bookshop/sample requests.http
Normal file
12
packages/bookshop/sample requests.http
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
### Submit Orders
|
||||||
|
POST http://localhost:4004/browse/Orders
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
{ "OrderNo":"2019-09...", "Items":[
|
||||||
|
{ "book_ID":201, "amount":5 }
|
||||||
|
]}
|
||||||
|
|
||||||
|
# Sending this three times should result in a 409: 5 exceeds stock for book #201
|
||||||
|
|
||||||
|
### Check books entity that stock was reduced
|
||||||
|
GET http://localhost:4004/admin/Books(201)
|
||||||
7
packages/bookshop/srv/admin-service.cds
Normal file
7
packages/bookshop/srv/admin-service.cds
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
|
service AdminService @(_requires:'admin') {
|
||||||
|
entity Books as projection on my.Books;
|
||||||
|
entity Movies as projection on my.Movies;
|
||||||
|
entity Authors as projection on my.Authors;
|
||||||
|
entity Orders as select from my.Orders;
|
||||||
|
}
|
||||||
10
packages/bookshop/srv/cat-service.cds
Normal file
10
packages/bookshop/srv/cat-service.cds
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using { sap.capire.bookshop as my } from '../db/schema';
|
||||||
|
service CatalogService @(path:'/browse') {
|
||||||
|
|
||||||
|
@readonly entity Books as SELECT from my.Books {*,
|
||||||
|
author.name as author
|
||||||
|
} excluding { createdBy, modifiedBy };
|
||||||
|
|
||||||
|
@requires_: 'authenticated-user'
|
||||||
|
@insertonly entity Orders as projection on my.Orders;
|
||||||
|
}
|
||||||
28
packages/bookshop/srv/cat-service.js
Normal file
28
packages/bookshop/srv/cat-service.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Implementation for CatalogService defined in ./cat-service.cds
|
||||||
|
*/
|
||||||
|
module.exports = (srv)=>{
|
||||||
|
|
||||||
|
// Use reflection to get the csn definition of Books
|
||||||
|
const {Books} = cds.entities
|
||||||
|
|
||||||
|
// Add some discount for overstocked books
|
||||||
|
srv.after ('READ','Books', (each)=>{
|
||||||
|
if (each.stock > 111) each.title += ' -- 11% discount!'
|
||||||
|
})
|
||||||
|
|
||||||
|
// Reduce stock of books upon incoming orders
|
||||||
|
srv.before ('CREATE','Orders', async (req)=>{
|
||||||
|
const tx = cds.transaction(req), order = req.data;
|
||||||
|
if (order.Items) {
|
||||||
|
const affectedRows = await tx.run(order.Items.map(item =>
|
||||||
|
UPDATE(Books) .where({ID:item.book_ID})
|
||||||
|
.and(`stock >=`, item.amount)
|
||||||
|
.set(`stock -=`, item.amount)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if (affectedRows.some(row => !row)) req.error(409, 'Sold out, sorry')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"build": {
|
|
||||||
"target": ".",
|
|
||||||
"tasks": []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
15
packages/bookstore/.gitignore
vendored
15
packages/bookstore/.gitignore
vendored
@@ -1,15 +0,0 @@
|
|||||||
.che/
|
|
||||||
.gen/
|
|
||||||
gen/
|
|
||||||
mta_archives/
|
|
||||||
node_modules/
|
|
||||||
target/
|
|
||||||
|
|
||||||
.cds_gen.log
|
|
||||||
connection.properties
|
|
||||||
*.db
|
|
||||||
.DS_Store
|
|
||||||
*.orig
|
|
||||||
_out
|
|
||||||
default-*.json
|
|
||||||
package-lock.json
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "bookstore",
|
|
||||||
"description": "Generated by cds init",
|
|
||||||
"repository": "<Add your repository here>",
|
|
||||||
"license": "ISC",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"engines": {
|
|
||||||
"node": "^8.9"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": "^3.16.3",
|
|
||||||
"@sap/cds-rest": "latest",
|
|
||||||
"express": "^4.17.1"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"build": "cds build/all --clean",
|
|
||||||
"deploy": "cds deploy",
|
|
||||||
"start": "cds run"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
12
packages/products-service/.gitignore
vendored
12
packages/products-service/.gitignore
vendored
@@ -1,12 +0,0 @@
|
|||||||
gen/
|
|
||||||
.gen/
|
|
||||||
node_modules/
|
|
||||||
target/
|
|
||||||
*.db
|
|
||||||
.DS_Store
|
|
||||||
_out
|
|
||||||
.che/
|
|
||||||
.cds_gen.log
|
|
||||||
package-lock.json
|
|
||||||
*.orig
|
|
||||||
mta_archives/
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
namespace sap.capire.products;
|
|
||||||
|
|
||||||
using { Currency, cuid, managed, sap.common.CodeList } from '@sap/cds/common';
|
|
||||||
|
|
||||||
entity Products : cuid, managed {
|
|
||||||
title : localized String(111);
|
|
||||||
descr : localized String(1111);
|
|
||||||
stock : Integer;
|
|
||||||
price : Decimal(9,2);
|
|
||||||
currency : Currency;
|
|
||||||
category : Association to Categories;
|
|
||||||
}
|
|
||||||
|
|
||||||
entity Categories : CodeList {
|
|
||||||
key ID : Integer;
|
|
||||||
parent : Association to Categories;
|
|
||||||
children : Composition of many Categories on children.parent = $self;
|
|
||||||
}
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
using from './db/schema';
|
|
||||||
using from './srv/admin-service';
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@sap/capire-products",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "A reuse package providing domain models and services to manage product catalogs.",
|
|
||||||
"repository": "https://github.wdf.sap.corp/caps/products-service.git",
|
|
||||||
"license": "ISC",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": "^3.16.3",
|
|
||||||
"express": "^4.17.1"
|
|
||||||
},
|
|
||||||
"files": [
|
|
||||||
"db",
|
|
||||||
"srv",
|
|
||||||
"index.cds"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
using { sap.capire.products as db } from '../db/schema';
|
|
||||||
namespace sap.capire.products;
|
|
||||||
|
|
||||||
service AdminService @(_requires:'admin') {
|
|
||||||
entity Products as projection on db.Products;
|
|
||||||
entity Categories as projection on db.Categories;
|
|
||||||
}
|
|
||||||
@@ -1,68 +0,0 @@
|
|||||||
const cds = require ('@sap/cds')
|
|
||||||
|
|
||||||
describe('reading/writing hierarchies', ()=>{
|
|
||||||
|
|
||||||
it ('should prepare to sqlite in-memory', async()=>{
|
|
||||||
await cds.deploy (__dirname+'/../db') .to ('sqlite::memory:')
|
|
||||||
expect (cds.model) .toBeDefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should insert hierarchy of categories', ()=>{
|
|
||||||
const { Categories } = cds.entities
|
|
||||||
return INSERT.into (Categories) .entries (
|
|
||||||
{ ID:100, name:'Some Sample Categories...', children:[
|
|
||||||
{ ID:101, name:'Cat', children:[
|
|
||||||
{ ID:102, name:'Kitty', children:[
|
|
||||||
{ ID:103, name:'Kitty Cat', children:[
|
|
||||||
{ ID:104, name:'Aristocat' } ]},
|
|
||||||
{ ID:105, name:'Kitty Bat' } ]},
|
|
||||||
{ ID:106, name:'Catwoman', children:[
|
|
||||||
{ ID:107, name:'Catalina' } ]} ]},
|
|
||||||
{ ID:108, name:'Catweazle' }
|
|
||||||
]}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should read categories with children', async()=>{
|
|
||||||
const { Categories } = cds.entities
|
|
||||||
expect (await
|
|
||||||
|
|
||||||
SELECT.one.from (Categories, c=>{
|
|
||||||
c.ID, c.name.as('parent'), c.children (c=>{
|
|
||||||
c.name.as('child')
|
|
||||||
})
|
|
||||||
}) .where ({name:'Cat'})
|
|
||||||
|
|
||||||
) .toMatchObject (
|
|
||||||
|
|
||||||
{ ID:101, parent:'Cat', children:[
|
|
||||||
{ child:'Kitty' },
|
|
||||||
{ child:'Catwoman' },
|
|
||||||
]}
|
|
||||||
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
it ('should read hierarchy of categories', async()=>{
|
|
||||||
const { Categories } = cds.entities
|
|
||||||
expect (await
|
|
||||||
|
|
||||||
SELECT.one.from (Categories, c=>{
|
|
||||||
c.ID, c.name, c.children (c=>{ c.name },{levels:3})
|
|
||||||
}) .where ({name:'Cat'})
|
|
||||||
|
|
||||||
) .toMatchObject (
|
|
||||||
|
|
||||||
{ ID:101, name:'Cat', children:[
|
|
||||||
{ name:'Kitty', children:[
|
|
||||||
{ name:'Kitty Cat', children:[
|
|
||||||
{ name:'Aristocat' }, ]},
|
|
||||||
{ name:'Kitty Bat' }, ]},
|
|
||||||
{ name:'Catwoman', children:[
|
|
||||||
{ name:'Catalina' } ]},
|
|
||||||
]}
|
|
||||||
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
ID;parent_ID;name
|
|
||||||
0;;Some Sample Categories...
|
|
||||||
1;;Cat
|
|
||||||
2;1;Kitty
|
|
||||||
3;2;Kitty Cat
|
|
||||||
4;3;Aristocat
|
|
||||||
5;2;Kitty Bat
|
|
||||||
6;1;Catwoman
|
|
||||||
7;6;Catalina
|
|
||||||
8;;Catweazle
|
|
||||||
|
@@ -1,157 +0,0 @@
|
|||||||
{
|
|
||||||
"info": {
|
|
||||||
"_postman_id": "0f8d4e79-a1c2-47fe-aeab-0319fb4ce180",
|
|
||||||
"name": "@sap/capire-products",
|
|
||||||
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
|
|
||||||
},
|
|
||||||
"item": [
|
|
||||||
{
|
|
||||||
"name": "Categories",
|
|
||||||
"request": {
|
|
||||||
"method": "POST",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "Content-Type",
|
|
||||||
"value": "application/json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": "{ \"ID\":0, \"name\":\"Some Sample Categories...\", \"children\":[\n { \"ID\":1, \"name\":\"Cat\", \"children\":[\n { \"ID\":2, \"name\":\"Kitty\", \"children\":[\n { \"ID\":3, \"name\":\"Kitty Cat\", \"children\":[\n { \"ID\":4, \"name\":\"Aristocat\" }\n ]},\n { \"ID\":5, \"name\":\"Kitty Bat\" }\n ]},\n { \"ID\":6, \"name\":\"Catwoman\", \"children\":[\n { \"ID\":7, \"name\":\"Catalina\" }\n ]}\n ] },\n { \"ID\":8, \"name\":\"Catweazle\" }\n]}\n"
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "http://localhost:4004/admin/cats",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"localhost"
|
|
||||||
],
|
|
||||||
"port": "4004",
|
|
||||||
"path": [
|
|
||||||
"admin",
|
|
||||||
"cats"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Categories",
|
|
||||||
"request": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"localhost"
|
|
||||||
],
|
|
||||||
"port": "4004",
|
|
||||||
"path": [
|
|
||||||
"admin",
|
|
||||||
"cats",
|
|
||||||
"0"
|
|
||||||
],
|
|
||||||
"query": [
|
|
||||||
{
|
|
||||||
"key": "$expand",
|
|
||||||
"value": "children($expand=children($expand=children($expand=children)))"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": [
|
|
||||||
{
|
|
||||||
"name": "Categories",
|
|
||||||
"originalRequest": {
|
|
||||||
"method": "GET",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "http://localhost:4004/admin/cats/0?$expand=children($expand=children($expand=children($expand=children)))",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"localhost"
|
|
||||||
],
|
|
||||||
"port": "4004",
|
|
||||||
"path": [
|
|
||||||
"admin",
|
|
||||||
"cats",
|
|
||||||
"0"
|
|
||||||
],
|
|
||||||
"query": [
|
|
||||||
{
|
|
||||||
"key": "$expand",
|
|
||||||
"value": "children($expand=children($expand=children($expand=children)))"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"status": "OK",
|
|
||||||
"code": 200,
|
|
||||||
"_postman_previewlanguage": "json",
|
|
||||||
"header": [
|
|
||||||
{
|
|
||||||
"key": "X-Powered-By",
|
|
||||||
"value": "Express"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "OData-Version",
|
|
||||||
"value": "4.0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "content-type",
|
|
||||||
"value": "application/json;odata.metadata=minimal"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "Date",
|
|
||||||
"value": "Tue, 21 May 2019 19:20:24 GMT"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "Connection",
|
|
||||||
"value": "keep-alive"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"key": "Content-Length",
|
|
||||||
"value": "767"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"cookie": [],
|
|
||||||
"body": "{\n \"@odata.context\": \"$metadata#cats(children(children(children(children()))))/$entity\",\n \"@odata.metadataEtag\": \"W/\\\"+AAp4JKNOcr+OusjrdQo55RCfM+UHKpTh8EbhsxyPhM=\\\"\",\n \"name\": \"Some Sample Categories...\",\n \"descr\": null,\n \"ID\": 0,\n \"parent_ID\": null,\n \"children\": [\n {\n \"name\": \"Cat\",\n \"descr\": null,\n \"ID\": 1,\n \"parent_ID\": 0,\n \"children\": [\n {\n \"name\": \"Kitty\",\n \"descr\": null,\n \"ID\": 2,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Kitty Cat\",\n \"descr\": null,\n \"ID\": 3,\n \"parent_ID\": 2,\n \"children\": [\n {\n \"name\": \"Aristocat\",\n \"descr\": null,\n \"ID\": 4,\n \"parent_ID\": 3\n }\n ]\n },\n {\n \"name\": \"Kitty Bat\",\n \"descr\": null,\n \"ID\": 5,\n \"parent_ID\": 2,\n \"children\": []\n }\n ]\n },\n {\n \"name\": \"Catwoman\",\n \"descr\": null,\n \"ID\": 6,\n \"parent_ID\": 1,\n \"children\": [\n {\n \"name\": \"Catalina\",\n \"descr\": null,\n \"ID\": 7,\n \"parent_ID\": 6,\n \"children\": []\n }\n ]\n }\n ]\n },\n {\n \"name\": \"Catweazle\",\n \"descr\": null,\n \"ID\": 8,\n \"parent_ID\": 0,\n \"children\": []\n }\n ]\n}"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Categories",
|
|
||||||
"request": {
|
|
||||||
"method": "DELETE",
|
|
||||||
"header": [],
|
|
||||||
"body": {
|
|
||||||
"mode": "raw",
|
|
||||||
"raw": ""
|
|
||||||
},
|
|
||||||
"url": {
|
|
||||||
"raw": "http://localhost:4004/admin/cats/0",
|
|
||||||
"protocol": "http",
|
|
||||||
"host": [
|
|
||||||
"localhost"
|
|
||||||
],
|
|
||||||
"port": "4004",
|
|
||||||
"path": [
|
|
||||||
"admin",
|
|
||||||
"cats",
|
|
||||||
"0"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"response": []
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "dev-env",
|
|
||||||
"author": "daniel.hutzel@sap.com",
|
|
||||||
"dependencies": {
|
|
||||||
"@sap/cds": "^3.16.3"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"sqlite3": "^4.0.7"
|
|
||||||
},
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "tests-env",
|
|
||||||
"author": "daniel.hutzel@sap.com",
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/jest": "*",
|
|
||||||
"jest": "^24.8.0",
|
|
||||||
"supertest": "^4.0.2"
|
|
||||||
},
|
|
||||||
"license": "ISC"
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user