Compare commits
19 Commits
using-upse
...
pdf
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b03529a4c | ||
|
|
bed293f1b2 | ||
|
|
50b13f60ce | ||
|
|
f889c27338 | ||
|
|
624c6c5c72 | ||
|
|
12fd91ca4f | ||
|
|
535981dc7e | ||
|
|
d15d0535d9 | ||
|
|
430d3a46c4 | ||
|
|
308e6b932a | ||
|
|
703d45fab0 | ||
|
|
63c21c5a96 | ||
|
|
e0c6b16b15 | ||
|
|
0771fc06e6 | ||
|
|
dc90cad8f4 | ||
|
|
f731a95bd1 | ||
|
|
2cd092be10 | ||
|
|
a1c2f32408 | ||
|
|
8a6a42f109 |
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": [
|
"extends": [
|
||||||
"eslint:recommended",
|
"plugin:@sap/cds/recommended",
|
||||||
"plugin:@sap/cds/recommended"
|
"eslint:recommended"
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"browser": true,
|
"browser": true,
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
"DELETE": true,
|
"DELETE": true,
|
||||||
"CREATE": true,
|
"CREATE": true,
|
||||||
"DROP": true,
|
"DROP": true,
|
||||||
|
"CDL": true,
|
||||||
|
"CQL": true,
|
||||||
"cds": true
|
"cds": true
|
||||||
},
|
},
|
||||||
"rules": {
|
"rules": {
|
||||||
|
|||||||
1
.registry/.gitignore
vendored
1
.registry/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
*.tgz
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
const { exec } = require ('child_process')
|
|
||||||
const isWin = process.platform === 'win32'
|
|
||||||
const express = require ('express')
|
|
||||||
const fs = require ('fs')
|
|
||||||
const app = express()
|
|
||||||
|
|
||||||
const { PORT=4444 } = process.env
|
|
||||||
const [,,port=PORT,scope='@capire'] = process.argv
|
|
||||||
const cwd = __dirname
|
|
||||||
|
|
||||||
// clean up on start (exit handler might not complete on Windows)
|
|
||||||
exec(isWin ? 'del *.tgz' : 'rm *.tgz', {cwd})
|
|
||||||
|
|
||||||
|
|
||||||
app.use('/-/:tarball', (req,res,next) => {
|
|
||||||
console.debug ('GET', req.params)
|
|
||||||
try {
|
|
||||||
const { tarball } = req.params
|
|
||||||
const pkgFull = tarball.substring(0, tarball.lastIndexOf('-'))
|
|
||||||
const [, pkg ] = /^\w+-(.+)/.exec(pkgFull)
|
|
||||||
fs.lstat(tarball,(err => {
|
|
||||||
if (err) console.debug (`npm pack ../${pkg}`)
|
|
||||||
if (err) exec(`npm pack ../${pkg}`,{cwd},next)
|
|
||||||
else next()
|
|
||||||
}))
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
res.sendStatus(500)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
app.use('/-', express.static(__dirname))
|
|
||||||
|
|
||||||
app.get('/*', (req,res)=>{
|
|
||||||
const urlRegex = /^\/(@[\w-]+)\/(.+)/
|
|
||||||
const url = decodeURIComponent(req.url)
|
|
||||||
console.debug ('GET',url)
|
|
||||||
try {
|
|
||||||
if (!urlRegex.test(url)) return res.sendStatus(404)
|
|
||||||
const [, scpe, pkg ] = urlRegex.exec(url)
|
|
||||||
const package = require (`${scpe}/${pkg}/package.json`)
|
|
||||||
const tarball = `${scpe.slice(1)}-${pkg}-${package.version}.tgz`
|
|
||||||
// https://github.com/npm/registry/blob/master/docs/responses/package-metadata.md
|
|
||||||
res.json({
|
|
||||||
"name": package.name,
|
|
||||||
"dist-tags": {
|
|
||||||
"latest": package.version
|
|
||||||
},
|
|
||||||
"versions": {
|
|
||||||
[package.version]: {
|
|
||||||
"name": package.name,
|
|
||||||
"version": package.version,
|
|
||||||
"dist": {
|
|
||||||
"tarball": `${server.url}/-/${tarball}`
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
})
|
|
||||||
} catch (e) {
|
|
||||||
if (e.code === 'MODULE_NOT_FOUND') return res.sendStatus(404)
|
|
||||||
console.error(e); throw e
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const server = app.listen(port, ()=>{
|
|
||||||
const url = server.url = `http://localhost:${server.address().port}`
|
|
||||||
console.log (`npm set ${scope}:registry=${url}`)
|
|
||||||
exec(`npm set ${scope}:registry=${url}`)
|
|
||||||
console.log (`${scope} registry listening on ${url}`)
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const _exit = ()=>{
|
|
||||||
server.close()
|
|
||||||
exec(`npm conf rm "${scope}:registry"`, ()=> { process.exit() })
|
|
||||||
}
|
|
||||||
|
|
||||||
process.on ('SIGTERM',_exit)
|
|
||||||
process.on ('SIGHUP',_exit)
|
|
||||||
process.on ('SIGINT',_exit)
|
|
||||||
process.on ('SIGUSR2',_exit)
|
|
||||||
20
.vscode/launch.json
vendored
20
.vscode/launch.json
vendored
@@ -13,7 +13,7 @@
|
|||||||
"<node_internals>/**",
|
"<node_internals>/**",
|
||||||
"**/node_modules/**",
|
"**/node_modules/**",
|
||||||
"**/cds/lib/lazy.js",
|
"**/cds/lib/lazy.js",
|
||||||
"**/cds/lib/req/cls.js",
|
"**/cds/lib/req/cds-context.js",
|
||||||
"**/odata-v4/okra/**"
|
"**/odata-v4/okra/**"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -26,10 +26,24 @@
|
|||||||
"<node_internals>/**",
|
"<node_internals>/**",
|
||||||
"**/node_modules/**",
|
"**/node_modules/**",
|
||||||
"**/cds/lib/lazy.js",
|
"**/cds/lib/lazy.js",
|
||||||
"**/cds/lib/req/cls.js",
|
"**/cds/lib/req/cds-context.js",
|
||||||
"**/odata-v4/okra/**"
|
"**/odata-v4/okra/**"
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "Debug Mocha Tests",
|
||||||
|
"type": "node",
|
||||||
|
"request": "attach",
|
||||||
|
"port": 9229,
|
||||||
|
"continueOnAttach": true,
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**",
|
||||||
|
"**/node_modules/**",
|
||||||
|
"**/cds/lib/lazy.js",
|
||||||
|
"**/cds/lib/req/cds-context.js",
|
||||||
|
"**/odata-v4/okra/**",
|
||||||
|
]
|
||||||
|
},
|
||||||
],
|
],
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
|
|||||||
5
.vscode/settings.json
vendored
5
.vscode/settings.json
vendored
@@ -10,12 +10,13 @@
|
|||||||
"<node_internals>/**",
|
"<node_internals>/**",
|
||||||
"**/node_modules/**",
|
"**/node_modules/**",
|
||||||
"**/cds/lib/lazy.js",
|
"**/cds/lib/lazy.js",
|
||||||
"**/cds/lib/req/cls.js",
|
"**/cds/lib/req/cds-context.js",
|
||||||
"**/odata-v4/okra/**"
|
"**/odata-v4/okra/**"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"mochaExplorer.debuggerConfig": "Debug Mocha Tests",
|
||||||
"mochaExplorer.parallel": true,
|
"mochaExplorer.parallel": true,
|
||||||
"eslint.validate": [
|
"eslint.probe": [
|
||||||
"cds",
|
"cds",
|
||||||
"csn",
|
"csn",
|
||||||
"csv",
|
"csv",
|
||||||
|
|||||||
@@ -4,21 +4,21 @@
|
|||||||
* currencies, if not obtained through @capire/common.
|
* currencies, if not obtained through @capire/common.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = async (db)=>{
|
module.exports = async (tx)=>{
|
||||||
|
|
||||||
const has_common = db.model.definitions['sap.common.Currencies'].elements.numcode
|
const has_common = tx.model.definitions['sap.common.Currencies']?.elements.numcode
|
||||||
if (has_common) return
|
if (has_common) return
|
||||||
|
|
||||||
const already_filled = await db.exists('sap.common.Currencies',{code:'EUR'})
|
const already_filled = await tx.exists('sap.common.Currencies',{code:'EUR'})
|
||||||
if (already_filled) return
|
if (already_filled) return
|
||||||
|
|
||||||
await INSERT.into ('sap.common.Currencies') .columns (
|
await tx.run (INSERT.into ('sap.common.Currencies') .columns (
|
||||||
'code','symbol','name'
|
[ 'code', 'symbol', 'name' ]
|
||||||
) .rows (
|
) .rows (
|
||||||
[ 'EUR','€','Euro' ],
|
[ 'EUR', '€', 'Euro' ],
|
||||||
[ 'USD','$','US Dollar' ],
|
[ 'USD', '$', 'US Dollar' ],
|
||||||
[ 'GBP','£','British Pound' ],
|
[ 'GBP', '£', 'British Pound' ],
|
||||||
[ 'ILS','₪','Shekel' ],
|
[ 'ILS', '₪', 'Shekel' ],
|
||||||
[ 'JPY','¥','Yen' ],
|
[ 'JPY', '¥', 'Yen' ],
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
using CatalogService from '@capire/bookstore';
|
using CatalogService from '@capire/bookstore';
|
||||||
|
|
||||||
|
using from '@sap/cds-pdf-export';
|
||||||
|
|
||||||
|
annotate CatalogService with @(
|
||||||
|
Capabilities: { SupportedFormats : [ 'application/pdf' ] },
|
||||||
|
PDF.Features: {
|
||||||
|
DocumentDescriptionReference : '/-pdf/',
|
||||||
|
DocumentDescriptionCollection : 'createDocumentDescription'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Books Object Page
|
// Books Object Page
|
||||||
|
|||||||
@@ -43,6 +43,16 @@
|
|||||||
"[production]": {
|
"[production]": {
|
||||||
"model": "db/hana"
|
"model": "db/hana"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"pdf": {
|
||||||
|
"kind": "btp-adobe-forms",
|
||||||
|
"vcap": {
|
||||||
|
"label": "adsrestapi"
|
||||||
|
},
|
||||||
|
"[pdfme]": {
|
||||||
|
"kind": "export-pdf",
|
||||||
|
"impl": "./pdfme.js"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hana": {
|
"hana": {
|
||||||
|
|||||||
38
fiori/pdfme.js
Normal file
38
fiori/pdfme.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
const { generate, BLANK_PDF } = require("@pdfme/generator");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate PDF with @pdfme/generator library
|
||||||
|
*/
|
||||||
|
module.exports = async (data, headers) => {
|
||||||
|
|
||||||
|
let inputs = data
|
||||||
|
|
||||||
|
let x = 0, y = 0;
|
||||||
|
const width = 30;
|
||||||
|
const height = 5;
|
||||||
|
|
||||||
|
const tableSchema = {}
|
||||||
|
for (const entry of headers) {
|
||||||
|
x += width;
|
||||||
|
tableSchema[entry.Name] = {
|
||||||
|
type: 'text',
|
||||||
|
position: { x, y: 10 },
|
||||||
|
width,
|
||||||
|
height
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const row of data) {
|
||||||
|
for (const [key, value] of Object.entries(row)) {
|
||||||
|
if (typeof value !== 'string') row[key] = ''+value // stringify
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const template = {
|
||||||
|
basePdf: BLANK_PDF,
|
||||||
|
schemas: [tableSchema]
|
||||||
|
};
|
||||||
|
const pdf = await generate({ template, inputs });
|
||||||
|
|
||||||
|
return pdf;
|
||||||
|
};
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
const cds = require("@sap/cds")
|
|
||||||
|
|
||||||
// install OData v2 adapter
|
// install OData v2 adapter
|
||||||
|
const cds = require("@sap/cds")
|
||||||
const proxy = require('@sap/cds-odata-v2-adapter-proxy')
|
const proxy = require('@sap/cds-odata-v2-adapter-proxy')
|
||||||
const proxyOpts = global.it ? { target:'auto' } : {} // for tests, set 'auto' to detect port dynamically
|
const opts = global.it ? { target:'auto' } : {} // for tests, set 'auto' to detect port dynamically
|
||||||
cds.on('bootstrap', app => app.use(proxy(proxyOpts)))
|
cds.on('bootstrap', app => app.use(proxy(opts))) // install proxy
|
||||||
|
cds.log('cov2ap','silent') // suppress anoying log outpout, e.g. for `npm run mocha -- --reporter nyan`
|
||||||
|
|
||||||
module.exports = require('@capire/bookstore/server.js')
|
module.exports = require('@capire/bookstore/server.js')
|
||||||
3456
package-lock.json
generated
3456
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@
|
|||||||
"./reviews"
|
"./reviews"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@sap/eslint-plugin-cds": "^2.6.1",
|
||||||
"axios": "^1",
|
"axios": "^1",
|
||||||
"chai": "^4.3.4",
|
"chai": "^4.3.4",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
@@ -29,13 +30,12 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
"cleanup": "rm -rf node_modules && rm -rf */node_modules && rm -rf */*/node_modules",
|
||||||
"registry": "node .registry/server.js",
|
|
||||||
"bookshop": "cds watch bookshop",
|
"bookshop": "cds watch bookshop",
|
||||||
"fiori": "cds watch fiori",
|
"fiori": "cds watch fiori",
|
||||||
"hello": "cds watch hello",
|
"hello": "cds watch hello",
|
||||||
"media": "cds watch media",
|
"media": "cds watch media",
|
||||||
"mocha": "npx mocha || echo",
|
"mocha": "CDS_TEST_SILENT=y npx mocha",
|
||||||
"jest": "npx jest",
|
"jest": "npx jest --silent",
|
||||||
"start": "cds watch fiori",
|
"start": "cds watch fiori",
|
||||||
"test": "npm run jest -- --silent",
|
"test": "npm run jest -- --silent",
|
||||||
"test:hello": "cd hello && npm test"
|
"test:hello": "cd hello && npm test"
|
||||||
@@ -48,7 +48,8 @@
|
|||||||
},
|
},
|
||||||
"mocha": {
|
"mocha": {
|
||||||
"recursive": true,
|
"recursive": true,
|
||||||
"parallel": true
|
"parallel": true,
|
||||||
|
"timeout": 6666
|
||||||
},
|
},
|
||||||
"license": "SAP SAMPLE CODE LICENSE",
|
"license": "SAP SAMPLE CODE LICENSE",
|
||||||
"private": true
|
"private": true
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Overview of Samples
|
# Overview of Samples
|
||||||
|
|
||||||
The following list gives an overview of the samples provided in subdirectories.
|
The following list gives an overview of the samples provided in subdirectories.
|
||||||
Each sub directory essentially is an individual npm package arranged in an [all-in-one monorepo](all-in-one-monorepo) umbrella setup.
|
Each sub directory essentially is an individual npm package arranged in an [all-in-one monorepo](#all-in-one-monorepo) umbrella setup.
|
||||||
|
|
||||||
|
|
||||||
## [@capire/hello-world](hello)
|
## [@capire/hello-world](hello)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ const cds = require('@sap/cds/lib')
|
|||||||
describe('cap/samples - Custom Handlers', () => {
|
describe('cap/samples - Custom Handlers', () => {
|
||||||
|
|
||||||
const { GET, POST, expect } = cds.test(__dirname+'/../bookshop')
|
const { GET, POST, expect } = cds.test(__dirname+'/../bookshop')
|
||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
beforeAll(()=>{
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
|
})
|
||||||
|
|
||||||
it('should reject out-of-stock orders', async () => {
|
it('should reject out-of-stock orders', async () => {
|
||||||
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
await POST `/browse/submitOrder ${{ book: 201, quantity: 5 }}`
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Fiori APIs - v2', () => {
|
describe('cap/samples - Fiori APIs - v2', function() {
|
||||||
|
|
||||||
const { GET, expect, axios } = cds.test ('@capire/fiori', '--with-mocks')
|
const { GET, expect, axios } = cds.test ('@capire/fiori', '--with-mocks')
|
||||||
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
||||||
|
|
||||||
|
// if (this.timeout) this.timeout(1e6)
|
||||||
|
|
||||||
it('serves $metadata documents in v2', async () => {
|
it('serves $metadata documents in v2', async () => {
|
||||||
const { headers, data } = await GET `/v2/browse/$metadata`
|
const { headers, data } = await GET `/v2/browse/$metadata`
|
||||||
expect(headers).to.contain({
|
expect(headers).to.contain({
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
const cds = require('@sap/cds/lib')
|
||||||
|
|
||||||
describe('cap/samples - Localized Data', () => {
|
describe('cap/samples - Localized Data', () => {
|
||||||
|
|
||||||
const { GET, expect, cds } = require('@sap/cds/lib').test (__dirname)
|
const { GET, expect } = cds.test (__dirname)
|
||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
beforeAll(()=>{
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
it('serves localized $metadata documents', async () => {
|
it('serves localized $metadata documents', async () => {
|
||||||
const { data } = await GET(`/browse/$metadata?sap-language=de`, { headers: { 'accept-language': 'de' }})
|
const { data } = await GET(`/browse/$metadata?sap-language=de`, { headers: { 'accept-language': 'de' }})
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
const cds = require('@sap/cds/lib')
|
const cds = require('@sap/cds/lib')
|
||||||
const {resolve} = require('path')
|
|
||||||
|
|
||||||
describe('cap/samples - Messaging', ()=>{
|
describe('cap/samples - Messaging', ()=>{
|
||||||
|
|
||||||
const { expect } = cds.test
|
const { expect } = cds.test.in(__dirname,'..')
|
||||||
const _model = '@capire/reviews'
|
const _model = '@capire/reviews'
|
||||||
const Reviews = 'sap.capire.reviews.Reviews'
|
const Reviews = 'sap.capire.reviews.Reviews'
|
||||||
if (cds.User.default) cds.User.default = cds.User.Privileged // hard core monkey patch
|
beforeAll(()=>{
|
||||||
else cds.User = cds.User.Privileged // hard core monkey patch for older cds releases
|
cds.User.default = cds.User.Privileged // hard core monkey patch
|
||||||
|
})
|
||||||
beforeAll(() => { cds.root = resolve(__dirname, '..') })
|
|
||||||
afterAll(() => { cds.root = process.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:')
|
||||||
@@ -35,6 +32,7 @@ describe('cap/samples - Messaging', ()=>{
|
|||||||
|
|
||||||
it ('should add review', async ()=>{
|
it ('should add review', async ()=>{
|
||||||
const review = { subject: "201", title: "Captivating", rating: ++N }
|
const review = { subject: "201", title: "Captivating", rating: ++N }
|
||||||
|
cds._debug = 1
|
||||||
const response = await srv.create ('Reviews') .entries (review)
|
const response = await srv.create ('Reviews') .entries (review)
|
||||||
expect (response) .to.containSubset (review)
|
expect (response) .to.containSubset (review)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,47 +4,6 @@ describe('cap/samples - Bookshop APIs', () => {
|
|||||||
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
const { GET, expect, axios } = cds.test ('@capire/bookshop')
|
||||||
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
axios.defaults.auth = { username: 'alice', password: 'admin' }
|
||||||
|
|
||||||
// Genres
|
|
||||||
const Drama = {
|
|
||||||
"name": "Drama",
|
|
||||||
"descr": null,
|
|
||||||
"ID": 11,
|
|
||||||
"parent_ID": 10
|
|
||||||
}
|
|
||||||
const Mystery = {
|
|
||||||
"name": "Mystery",
|
|
||||||
"descr": null,
|
|
||||||
"ID": 16,
|
|
||||||
"parent_ID": 10
|
|
||||||
}
|
|
||||||
const Romance = {
|
|
||||||
"name": "Romance",
|
|
||||||
"descr": null,
|
|
||||||
"ID": 15,
|
|
||||||
"parent_ID": 10
|
|
||||||
}
|
|
||||||
|
|
||||||
// Currencies
|
|
||||||
const GBP = {
|
|
||||||
"name": "British Pound",
|
|
||||||
"descr": null,
|
|
||||||
"code": "GBP",
|
|
||||||
"symbol": "£"
|
|
||||||
}
|
|
||||||
const USD = {
|
|
||||||
"name": "US Dollar",
|
|
||||||
"descr": null,
|
|
||||||
"code": "USD",
|
|
||||||
"symbol": "$"
|
|
||||||
}
|
|
||||||
const JPY = {
|
|
||||||
"name": "Yen",
|
|
||||||
"descr": null,
|
|
||||||
"code": "JPY",
|
|
||||||
"symbol": "¥"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -57,6 +16,9 @@ describe('cap/samples - Bookshop APIs', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
it('serves ListOfBooks?$expand=genre,currency', async () => {
|
||||||
|
const Mystery = { ID: 16, name: 'Mystery', descr: null, parent_ID: 10 }
|
||||||
|
const Romance = { ID: 15, name: 'Romance', descr: null, parent_ID: 10 }
|
||||||
|
const USD = { code: 'USD', name: 'US Dollar', descr: null, symbol: '$' }
|
||||||
const { data } = await GET `/browse/ListOfBooks ${{
|
const { data } = await GET `/browse/ListOfBooks ${{
|
||||||
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
params: { $search: 'Po', $select: `title,author`, $expand:`genre,currency` },
|
||||||
}}`
|
}}`
|
||||||
@@ -126,14 +88,10 @@ describe('cap/samples - Bookshop APIs', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('serves user info', async () => {
|
it('serves user info', async () => {
|
||||||
{
|
const { data: alice } = await GET `/user/me`
|
||||||
const { data } = await GET (`/user/me`)
|
expect(alice).to.containSubset({ id: 'alice', locale:'en' })
|
||||||
expect(data).to.containSubset({ id: 'alice', locale:'en' })
|
const { data: joe } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
||||||
}
|
expect(joe).to.containSubset({ id: 'joe', locale:'en' })
|
||||||
{
|
|
||||||
const { data } = await GET (`/user/me`, {auth: { username: 'joe' }})
|
|
||||||
expect(data).to.containSubset({ id: 'joe', locale:'en' })
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
|
|
||||||
const cds = require('@sap/cds/lib')
|
|
||||||
const { fork } = require('child_process')
|
|
||||||
const { resolve } = require('path')
|
|
||||||
const verbose = process.env.CDS_TEST_VERBOSE
|
|
||||||
|
|
||||||
describe('cap/samples - Local NPM registry', () => {
|
|
||||||
|
|
||||||
const { expect } = cds.test
|
|
||||||
// ||true
|
|
||||||
|
|
||||||
let registry
|
|
||||||
let axios
|
|
||||||
const cwd = resolve(__dirname, '..')
|
|
||||||
|
|
||||||
before(async ()=> {
|
|
||||||
const env = Object.assign(process.env, {PORT:'0'})
|
|
||||||
const res = await exec (resolve(cwd, '.registry/server.js'), {cwd, stdio: 'pipe', env})
|
|
||||||
registry = res.cp
|
|
||||||
axios = require('axios').create ({ baseURL: res.url, validateStatus: (status)=>status<500 })
|
|
||||||
})
|
|
||||||
|
|
||||||
after(done => { registry.once('exit',done); registry.kill() })
|
|
||||||
|
|
||||||
for (const mod of ['bookshop', 'data-viewer', 'fiori','orders','reviews']) {
|
|
||||||
it(`should serve ${mod}`, async () => {
|
|
||||||
const resp = await axios.get(`/@capire/${mod}`)
|
|
||||||
expect(resp.data).to.containSubset({name: `@capire/${mod}`, versions:{}})
|
|
||||||
const versions = Object.values(resp.data.versions)
|
|
||||||
await axios.get(versions[0].dist.tarball)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
it(`should return 404 for unknown packages`, async () => {
|
|
||||||
let resp = await axios.get(`/@capire/foo`)
|
|
||||||
expect(resp.status).to.equal(404)
|
|
||||||
resp = await axios.get(`/foo`)
|
|
||||||
expect(resp.status).to.equal(404)
|
|
||||||
})
|
|
||||||
|
|
||||||
})
|
|
||||||
|
|
||||||
function exec (script, opts) {
|
|
||||||
return new Promise((resolve, reject)=> {
|
|
||||||
const cp = fork (script, [], opts)
|
|
||||||
.on('error', err => reject(new Error(err)))
|
|
||||||
cp.stdout.on('data', chunk => {
|
|
||||||
if (verbose) console.log(chunk.toString())
|
|
||||||
if (chunk.toString().match(/listening.*(http:.*:\d+)/i)) {
|
|
||||||
resolve({cp, url:RegExp.$1})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
cp.stderr.on('data', chunk => {
|
|
||||||
if (verbose) console.error(chunk.toString())
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user