Compare commits

...

12 Commits

Author SHA1 Message Date
D051920
ae20e682be Change list object in tests 2020-08-12 11:18:21 +02:00
D051920
53527aac50 Change list object in tests 2020-08-12 10:39:20 +02:00
D051920
04f9f2a06f Change list object in tests 2020-08-12 10:18:12 +02:00
D051920
fff62e68f1 Merge branches 'enable-fixed-tests' and 'master' of https://github.com/SAP-samples/cloud-cap-samples into enable-fixed-tests 2020-08-12 09:56:11 +02:00
Daniel Hutzel
bd65af43eb Merge pull request #125 from SAP-samples/simplified-reviewed
Simplified reviewed/server.js
2020-08-10 23:24:51 +02:00
Daniel
6f9133cd4f Simplified reviewed/server.js 2020-08-06 19:32:07 +02:00
Daniel Hutzel
441c82b4c9 Merge pull request #123 from SAP-samples/Pinning-Fiori-to-last-known-good
Pinning Fiori to last-known-good
2020-08-01 14:47:30 +02:00
Daniel
fa7cff4123 Pinning Fiori to last-known-good 2020-08-01 14:44:13 +02:00
Christian Georgi
1b69064752 Make cuid.ID Core.Computed for now
+ TODO to check w/ Fiori
2020-07-31 17:18:14 +02:00
Christian Georgi
ada05cf279 Cosmetics 2020-07-31 16:28:08 +02:00
Christian Georgi
4b78a8b637 Do no longer use run blocks - removed in cds 4 2020-07-31 16:28:08 +02:00
D051920
ade170367b Enable temporary disabled test 2020-07-30 16:33:28 +02:00
7 changed files with 55 additions and 46 deletions

View File

@@ -40,7 +40,8 @@
</script>
<script src="https://sapui5.hana.ondemand.com/test-resources/sap/ushell/bootstrap/sandbox.js"></script>
<script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
<!-- <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" -->
<script 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-compatVersion="edge"
data-sap-ui-theme="sap_fiori_3"

View File

@@ -6,14 +6,14 @@ module.exports = cds.service.impl(function() {
// Reduce stock of ordered books if available stock suffices
this.before ('CREATE', 'Orders', (req) => {
const { Items: OrderItems } = req.data
return cds.transaction(req) .run (()=> OrderItems.map (order =>
UPDATE (Books) .where ('ID =', order.book_ID)
.and ('stock >=', order.amount)
.set ('stock -=', order.amount)
const { Items: items } = req.data
return cds.transaction(req) .run (items.map (item =>
UPDATE (Books) .where ('ID =', item.book_ID)
.and ('stock >=', item.amount)
.set ('stock -=', item.amount)
)) .then (all => all.forEach ((affectedRows,i) => {
if (affectedRows === 0) req.error (409,
`${OrderItems[i].amount} exceeds stock for book #${OrderItems[i].book_ID}`
`${items[i].amount} exceeds stock for book #${items[i].book_ID}`
)
}))
})

View File

@@ -3,37 +3,30 @@
// This is an example of using a project-local server.js to intercept
// the default bootstrapping process.
//
const cds = require ('@sap/cds')
// Mashup services after all are served...
cds.once('served', async()=>{
// Connect CatalogService and ReviewsService when all are served...
cds.once('served', async ({CatalogService}) => {
// react on event messages from reviews service
// reflect entity definitions used below...
const { Books } = cds.entities('sap.capire.bookshop')
const { Reviews } = cds.entities('ReviewsService')
// prepend the following handler so it overrides the default handler
CatalogService.prepend (srv => srv.on ('READ', 'Books/reviews', (req) => {
console.debug ('> delegating request to ReviewsService')
const [id] = req.params, { columns, limit } = req.query.SELECT
return SELECT(columns).from(Reviews).limit(limit).where({subject:String(id)})
}))
// subscribe to events emitted by ReviewsService
const ReviewsService = await cds.connect.to ('ReviewsService')
const db = await cds.connect.to ('db')
// reflect entities required below...
const { Books } = db.entities('sap.capire.bookshop')
const { Reviews } = ReviewsService.entities
ReviewsService.on ('reviewed', (msg) => {
console.debug ('> received:', msg.event, msg.data)
const { subject, rating } = msg.data
const tx = db.tx (msg) // TODO: db.tx(msg) fully implemented?
return tx.update (Books,subject) .with ({rating})
return UPDATE(Books,subject).with({rating})
})
// delegate requests to read reviews to ReviewsService
const CatalogService = await cds.connect.to ('CatalogService')
CatalogService.impl (srv => srv.on ('READ', 'Books/reviews', (req) => {
console.debug ('> delegating to ReviewsService')
const [ id ] = req.params
const tx = ReviewsService.tx(req)
return tx.read (Reviews) .where ({ subject: String(id) })
.columns (req.query.SELECT.columns)
}))
})
// Other bootstrapping events you could hook in to...
@@ -42,14 +35,9 @@ cds.on('bootstrap',(app) => {/* ... */})
cds.on('loaded', (model) => {/* ... */})
cds.on('connect', (srv) => {/* ... */})
cds.on('serving', (srv) => {/* ... */})
cds.once('served', (all) => {/* ... */})
cds.once('listening', ({server,url}) => {/* ... */})
// Delegate bootstrapping to built-in server.js
module.exports = cds.server
// Monkey-patching older releases
if (cds.version < '3.33.4') cds.once('listening', ()=> cds.emit('served'))
// Launch server if started directly from command-line
if (!module.parent) cds.server()

View File

@@ -31,7 +31,8 @@ GET {{bookshop}}/browse/Books(201)/reviews?
### Alternative OData URL
GET {{bookshop}}/browse/Books/201/reviews?
&$select=rating,date,reviewer,title
&$select=rating,date,title
&$top=3
###
GET {{bookshop}}/browse/Books(201)?

View File

@@ -1,2 +1,3 @@
cds.requires.messaging.kind = file-based-messaging
cds.odata.skipValidation = true
PORT = 5005

View File

@@ -261,7 +261,7 @@ describe('cds.ql → cqn', () => {
// same for works distinct
})
test.skip('where ( ... cql | {x:y} )', () => {
test('where ( ... cql | {x:y} )', () => {
const args = [`foo`, "'bar'", 3]
const ID = 11
@@ -278,7 +278,6 @@ describe('cds.ql → cqn', () => {
from: { ref: ['Foo'] },
where: cdr
? [
// '(', //> this one is not required
{ ref: ['ID'] },
'=',
{ val: ID },
@@ -287,7 +286,7 @@ describe('cds.ql → cqn', () => {
'in',
{ val: args },
'and',
'(', //> this one is missing, and that's changing the logic -> that's a BUG
'(',
{ ref: ['x'] },
'like',
{ val: '%x%' },
@@ -298,7 +297,6 @@ describe('cds.ql → cqn', () => {
')',
]
: [
'(', //> this one is not required
{ ref: ['ID'] },
'=',
{ val: ID },
@@ -307,7 +305,7 @@ describe('cds.ql → cqn', () => {
'in',
{ val: args },
'and',
// '(', //> this one is missing, and that's changing the logic -> that's a BUG
'(',
{ ref: ['x'] },
'like',
{ val: '%x%' },
@@ -337,11 +335,31 @@ describe('cds.ql → cqn', () => {
{ val: 'bar' },
',',
{ val: 3 },
')',
],
},
')'
]
}
})
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqn)
const cqnFluent = {
SELECT: {
from: { ref: ['Foo'] },
where: [
{ ref: ['ID'] },
'=',
{ val: ID },
'and',
{ ref: ['x'] },
'in',
{ list: [
{ val: 'foo' },
{ val: 'bar' },
{ val: 3 }
] }
]
}
}
expect(SELECT.from(Foo).where(`ID=`, ID, `and x in`, args)).to.eql(cqnFluent)
expect(SELECT.from(Foo).where(`ID=${ID} and x in (${args})`)).to.eql(cqn)
expect(

View File

@@ -72,7 +72,7 @@ describe('Localized Data', () => {
])
})
xit('supports @cds.localized:false', async ()=>{
it('supports @cds.localized:false', async ()=>{
const { data } = await GET(`/browse/BooksSans?&$select=title,localized_title&$expand=currency&$filter=locale eq 'de' or locale eq null`, {
headers: { 'Accept-Language': 'de' },
})