From ff351455dd1d201b464f4dc51fc8e78d65a3082a Mon Sep 17 00:00:00 2001 From: I051442 Date: Thu, 11 Jun 2020 15:35:06 +0200 Subject: [PATCH 01/19] Update for sap.fe usage starting with UI5 1.78 --- fiori/app/admin/webapp/Component.js | 9 ++++++--- fiori/app/admin/webapp/manifest.json | 2 +- fiori/app/browse/webapp/Component.js | 10 ++++++---- fiori/app/browse/webapp/manifest.json | 2 +- fiori/app/orders/webapp/Component.js | 9 ++++++--- fiori/app/orders/webapp/manifest.json | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/fiori/app/admin/webapp/Component.js b/fiori/app/admin/webapp/Component.js index 18967b84..c3137017 100644 --- a/fiori/app/admin/webapp/Component.js +++ b/fiori/app/admin/webapp/Component.js @@ -1,5 +1,8 @@ -sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("admin.Component", { - metadata:{ manifest:'json' } -})) +sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) { + "use strict"; + return AppComponent.extend("admin.Component", { + metadata: { manifest: "json" } + }); +}); /* eslint no-undef:0 */ \ No newline at end of file diff --git a/fiori/app/admin/webapp/manifest.json b/fiori/app/admin/webapp/manifest.json index 574480f1..25047c29 100644 --- a/fiori/app/admin/webapp/manifest.json +++ b/fiori/app/admin/webapp/manifest.json @@ -24,7 +24,7 @@ "sap.ui5": { "dependencies": { "libs": { - "sap.fe": {} + "sap.fe.templates": {} } }, "models": { diff --git a/fiori/app/browse/webapp/Component.js b/fiori/app/browse/webapp/Component.js index 0d8d14b5..7914d295 100644 --- a/fiori/app/browse/webapp/Component.js +++ b/fiori/app/browse/webapp/Component.js @@ -1,5 +1,7 @@ -sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("bookshop.Component", { - metadata:{ manifest:'json' } -})) - +sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) { + "use strict"; + return AppComponent.extend("bookshop.Component", { + metadata: { manifest: "json" } + }); +}); /* eslint no-undef:0 */ \ No newline at end of file diff --git a/fiori/app/browse/webapp/manifest.json b/fiori/app/browse/webapp/manifest.json index 4212312e..4a2e0a62 100644 --- a/fiori/app/browse/webapp/manifest.json +++ b/fiori/app/browse/webapp/manifest.json @@ -24,7 +24,7 @@ "sap.ui5": { "dependencies": { "libs": { - "sap.fe": {} + "sap.fe.templates": {} } }, "models": { diff --git a/fiori/app/orders/webapp/Component.js b/fiori/app/orders/webapp/Component.js index 82388965..dff3acbc 100644 --- a/fiori/app/orders/webapp/Component.js +++ b/fiori/app/orders/webapp/Component.js @@ -1,5 +1,8 @@ -sap.ui.define(["sap/fe/core/AppComponent"], ac => ac.extend("orders.Component", { - metadata:{ manifest:'json' } -})) +sap.ui.define(["sap/fe/core/AppComponent"], function(AppComponent) { + "use strict"; + return AppComponent.extend("orders.Component", { + metadata: { manifest: "json" } + }); +}); /* eslint no-undef:0 */ \ No newline at end of file diff --git a/fiori/app/orders/webapp/manifest.json b/fiori/app/orders/webapp/manifest.json index ce659ec2..df686462 100644 --- a/fiori/app/orders/webapp/manifest.json +++ b/fiori/app/orders/webapp/manifest.json @@ -24,7 +24,7 @@ "sap.ui5": { "dependencies": { "libs": { - "sap.fe": {} + "sap.fe.templates": {} } }, "models": { From 604cc0514ca96a0769cc62b85b413d344bf21d5f Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 19 Jun 2020 09:51:37 +0200 Subject: [PATCH 02/19] Running all mocha tests in parallel --- .mocharc.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .mocharc.yml diff --git a/.mocharc.yml b/.mocharc.yml new file mode 100644 index 00000000..06f6886f --- /dev/null +++ b/.mocharc.yml @@ -0,0 +1 @@ +parallel: true From 660344b6234aee31ea5eb3f82fb494e2bdf98f25 Mon Sep 17 00:00:00 2001 From: ianquigley-sap Date: Wed, 24 Jun 2020 11:00:03 +0100 Subject: [PATCH 03/19] Delete .npmrc The @sap scoped registry should now point to registry.npmjs.org rather than npm.sap.com. Please see https://jam4.sapjam.com/feed/item/eOtNGT1RSxVzknBtpSy2My for full details on the migration. npm.sap.com will not be updated going forward for the CDS library --- .npmrc | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .npmrc diff --git a/.npmrc b/.npmrc deleted file mode 100644 index 6041b7e8..00000000 --- a/.npmrc +++ /dev/null @@ -1 +0,0 @@ -@sap:registry=https://npm.sap.com \ No newline at end of file From fd796b54ef1769e656515c3becb50fef1563498d Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Wed, 24 Jun 2020 17:59:32 +0200 Subject: [PATCH 04/19] Redirect to community --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 294f3191..dd41eff5 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ npx jest ## Get Support Check out the documentation at [https://cap.cloud.sap](https://cap.cloud.sap).
-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). +In case you have a question, find a bug, or otherwise need support, please use our [community](https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce). ## License From 5ba69b50218beff92e349cfd5d1ab252bb7bf901 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Wed, 24 Jun 2020 18:11:04 +0200 Subject: [PATCH 05/19] Update issue templates --- .github/ISSUE_TEMPLATE/question--feedback-or-bug-.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/question--feedback-or-bug-.md diff --git a/.github/ISSUE_TEMPLATE/question--feedback-or-bug-.md b/.github/ISSUE_TEMPLATE/question--feedback-or-bug-.md new file mode 100644 index 00000000..19f10800 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question--feedback-or-bug-.md @@ -0,0 +1,10 @@ +--- +name: Question, feedback or bug? +about: Use our community! +title: '' +labels: '' +assignees: '' + +--- + +Please use our community on https://answers.sap.com/tags/9f13aee1-834c-4105-8e43-ee442775e5ce From 7b1c3d8b3a750c34a266bb7590494355e0f06719 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Thu, 2 Jul 2020 18:42:27 +0200 Subject: [PATCH 06/19] More UI annotations Make sure all entities can be properly displayed in Fiori preview. Especially UI.LineItems seems to be mandatory in newer Fiori versions. --- .../db/data/sap.capire.bookshop-Genres.csv | 2 +- common/data/sap.common-Currencies.csv | 2 +- fiori/app/_i18n/i18n.properties | 12 + fiori/app/common.cds | 213 ++++++++++++++++-- 4 files changed, 209 insertions(+), 20 deletions(-) diff --git a/bookshop/db/data/sap.capire.bookshop-Genres.csv b/bookshop/db/data/sap.capire.bookshop-Genres.csv index 08435ca9..1ea3793b 100644 --- a/bookshop/db/data/sap.capire.bookshop-Genres.csv +++ b/bookshop/db/data/sap.capire.bookshop-Genres.csv @@ -11,6 +11,6 @@ ID;parent_ID;name 19;10;Fairy Tale 20;;Non-Fiction 21;20;Biography -22;20;Autobiography +22;21;Autobiography 23;20;Essay 24;20;Speech diff --git a/common/data/sap.common-Currencies.csv b/common/data/sap.common-Currencies.csv index 63372602..efe4538e 100644 --- a/common/data/sap.common-Currencies.csv +++ b/common/data/sap.common-Currencies.csv @@ -2,7 +2,7 @@ code;symbol;name;descr;numcode;minor;exponent EUR;€;Euro;European Euro;978;Cent;2 USD;$;US Dollar;United States Dollar;840;Cent;2 CAD;$;Canadian Dollar;Canadian Dollar;124;Cent;2 -AUD;$;Australian Dollar;Canadian Dollar;036;Cent;2 +AUD;$;Australian Dollar;Australian Dollar;036;Cent;2 GBP;£;British Pound;Great Britain Pound;826;Penny;2 ILS;₪;Shekel;Israeli New Shekel;376;Agorat;2 INR;₹;Rupee;Indian Rupee;356;Paise;2 diff --git a/fiori/app/_i18n/i18n.properties b/fiori/app/_i18n/i18n.properties index 5d6f03d6..c1d0293f 100644 --- a/fiori/app/_i18n/i18n.properties +++ b/fiori/app/_i18n/i18n.properties @@ -7,7 +7,19 @@ AuthorID = Author ID Stock = Stock Name = Name AuthorName = Author's Name +DateOfBirth = Date of Birth +DateOfDeath = Date of Death +PlaceOfBirth = Place of Birth +PlaceOfDeath = Place of Death Authors = Authors Order = Order Orders = Orders Price = Price + +Genre = Genre +Genres = Genres +SubGenres = Sub Genres + +NumCode = Numeric Code +MinorUnit = Minor Unit +Exponent = Exponent \ No newline at end of file diff --git a/fiori/app/common.cds b/fiori/app/common.cds index 2cbdd162..614f03b3 100644 --- a/fiori/app/common.cds +++ b/fiori/app/common.cds @@ -1,9 +1,9 @@ /* - Common Annotations shared by all apps + Common Annotations shared by all apps */ using { sap.capire.bookshop as my } from '@capire/bookshop'; - +using { sap.common } from '@capire/common'; //////////////////////////////////////////////////////////////////////////// // @@ -13,7 +13,7 @@ annotate my.Books with @( Common.SemanticKey: [title], UI: { Identification: [{Value:title}], - SelectionFields: [ ID, author_ID, price, currency_code ], + SelectionFields: [ ID, author_ID, price, currency_code ], LineItem: [ {Value: ID}, {Value: title}, @@ -28,25 +28,18 @@ annotate my.Books with @( author @ValueList.entity:'Authors'; }; -annotate my.Authors with @( - UI: { - Identification: [{Value:name}], - } -); - - //////////////////////////////////////////////////////////////////////////// // // Books Details // annotate my.Books with @( UI: { - HeaderInfo: { - TypeName: '{i18n>Book}', - TypeNamePlural: '{i18n>Books}', - Title: {Value: title}, - Description: {Value: author.name} - }, + HeaderInfo: { + TypeName: '{i18n>Book}', + TypeNamePlural: '{i18n>Books}', + Title: {Value: title}, + Description: {Value: author.name} + }, } ); @@ -66,15 +59,199 @@ annotate my.Books with { descr @UI.MultiLineText; } +//////////////////////////////////////////////////////////////////////////// +// +// Genres List +// +annotate my.Genres with @( + Common.SemanticKey: [name], + UI: { + SelectionFields: [ name ], + LineItem:[ + {Value: name}, + {Value: parent.name, Label: 'Main Genre'}, + ], + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Genre Details +// +annotate my.Genres with @( + UI: { + Identification: [{Value:name}], + HeaderInfo: { + TypeName: '{i18n>Genre}', + TypeNamePlural: '{i18n>Genres}', + Title: {Value: name}, + Description: {Value: ID} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Label: '{i18n>SubGenres}', Target: 'children/@UI.LineItem'}, + ], + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Genres Elements +// annotate my.Genres with { - name @title: '{i18n>Genre}'; + ID @title: '{i18n>ID}'; + name @title: '{i18n>Genre}'; } +//////////////////////////////////////////////////////////////////////////// +// +// Authors List +// +annotate my.Authors with @( + Common.SemanticKey: [name], + UI: { + Identification: [{Value:name}], + SelectionFields: [ name ], + LineItem:[ + {Value: ID}, + {Value: name}, + {Value: dateOfBirth}, + {Value: dateOfDeath}, + {Value: placeOfBirth}, + {Value: placeOfDeath}, + ], + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Author Details +// +annotate my.Authors with @( + UI: { + HeaderInfo: { + TypeName: '{i18n>Author}', + TypeNamePlural: '{i18n>Authors}', + Title: {Value: name}, + Description: {Value: dateOfBirth} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Target: 'books/@UI.LineItem'}, + ], + } +); + + //////////////////////////////////////////////////////////////////////////// // // Authors Elements // annotate my.Authors with { ID @title:'{i18n>ID}' @UI.HiddenFilter; - name @title:'{i18n>AuthorName}'; + name @title:'{i18n>Name}'; + dateOfBirth @title:'{i18n>DateOfBirth}'; + dateOfDeath @title:'{i18n>DateOfDeath}'; + placeOfBirth @title:'{i18n>PlaceOfBirth}'; + placeOfDeath @title:'{i18n>PlaceOfDeath}'; +} + +//////////////////////////////////////////////////////////////////////////// +// +// Languages List +// +annotate common.Languages with @( + Common.SemanticKey: [code], + Identification: [{Value:code}], + UI: { + SelectionFields: [ name, descr ], + LineItem:[ + {Value: code}, + {Value: name}, + ], + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Language Details +// +annotate common.Languages with @( + UI: { + HeaderInfo: { + TypeName: '{i18n>Language}', + TypeNamePlural: '{i18n>Languages}', + Title: {Value: name}, + Description: {Value: descr} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, + ], + FieldGroup#Details: { + Data: [ + {Value: code}, + {Value: name}, + {Value: descr} + ] + }, + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Currencies List +// +annotate common.Currencies with @( + Common.SemanticKey: [code], + Identification: [{Value:code}], + UI: { + SelectionFields: [ name, descr ], + LineItem:[ + {Value: descr}, + {Value: symbol}, + {Value: code}, + ], + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Currency Details +// +annotate common.Currencies with @( + UI: { + HeaderInfo: { + TypeName: '{i18n>Currency}', + TypeNamePlural: '{i18n>Currencies}', + Title: {Value: descr}, + Description: {Value: code} + }, + Facets: [ + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Details}', Target: '@UI.FieldGroup#Details'}, + {$Type: 'UI.ReferenceFacet', Label: '{i18n>Extended}', Target: '@UI.FieldGroup#Extended'}, + ], + FieldGroup#Details: { + Data: [ + {Value: name}, + {Value: symbol}, + {Value: code}, + {Value: descr} + ] + }, + FieldGroup#Extended: { + Data: [ + {Value: numcode}, + {Value: minor}, + {Value: exponent} + ] + }, + } +); + +//////////////////////////////////////////////////////////////////////////// +// +// Currencies Elements +// +annotate common.Currencies with { + numcode @title:'{i18n>NumCode}'; + minor @title:'{i18n>MinorUnit}'; + exponent @title:'{i18n>Exponent}'; } From 522ec8e0714ecf712f44a9e9fcb674f32e597f59 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 7 Jul 2020 17:29:30 +0200 Subject: [PATCH 07/19] Simplified debugging --- .vscode/launch.json | 18 +++++------------- package.json | 2 ++ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 37d9ac7f..d0f0e8eb 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,24 +6,16 @@ "configurations": [ { "name": "bookshop", - "cwd": "${workspaceFolder}/bookshop", + "command": "cds watch bookshop", "request": "launch", - "type": "node", - "runtimeExecutable": "npx", - "runtimeArgs": ["-n"], - "args": ["--", "cds", "run", "--with-mocks", "--in-memory?"], - "console": "integratedTerminal", + "type": "node-terminal", "skipFiles": ["/**"] }, { - "name": "Fiori App", - "cwd": "${workspaceFolder}/fiori", + "name": "Fiori app", + "command": "cds watch fiori", "request": "launch", - "type": "node", - "runtimeExecutable": "npx", - "runtimeArgs": ["-n"], - "args": ["--", "cds", "run", "--with-mocks", "--in-memory?"], - "console": "integratedTerminal", + "type": "node-terminal", "skipFiles": ["/**"] } ], diff --git a/package.json b/package.json index f29d83fa..41936c96 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,8 @@ "sqlite3": "^4" }, "scripts": { + "bookshop": "cds watch bookshop", + "fiori": "cds watch fiori", "mocha": "npx mocha || echo", "jest": "npx jest --verbose", "test": "npm run jest -s" From 0f026ed56c7c3368bcdb7fe7491fcc5d2351d8e4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Jul 2020 10:37:35 +0200 Subject: [PATCH 08/19] It's finally out... --- .vscode/extensions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index dcc16d69..240b1cf9 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -4,7 +4,7 @@ // List of extensions which should be recommended for users of this workspace. "recommendations": [ - // "CDS Editor !", + "SAPSE.vscode-cds", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode", "mechatroner.rainbow-csv", From a3e4865d97eeae436a2a0132606fcdce29a59655 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 17 Jul 2020 01:03:30 +0200 Subject: [PATCH 09/19] Fixed messaging test --- test/messaging.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/messaging.test.js b/test/messaging.test.js index da3e9943..162db381 100644 --- a/test/messaging.test.js +++ b/test/messaging.test.js @@ -21,7 +21,7 @@ describe('Messaging', ()=>{ let N=0, received=[], M=0 it ('should add messaging event handlers', ()=>{ - srv.on('reviewed', (msg)=> received.push(msg)) + srv.on('reviewed', (msg)=> {received.push(msg)}) }) it ('should add more messaging event handlers', ()=>{ From de54f7057025d8f6a6ef1387f4348029b800e860 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 17 Jul 2020 01:45:43 +0200 Subject: [PATCH 10/19] Prepare tests for upcomming rel 4 --- test/cds.ql.test.js | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/test/cds.ql.test.js b/test/cds.ql.test.js index 3ecdf19b..6b3b277a 100644 --- a/test/cds.ql.test.js +++ b/test/cds.ql.test.js @@ -466,47 +466,38 @@ describe('cds.ql → cqn', () => { UPDATE.with allows to pass in plain data payloads, e.g. as obtained from REST clients. In addition, UPDATE.with supports specifying expressions, either in CQL fragements notation or as simple expression objects. - */ - test('with', () => { - expect(UPDATE(Foo).with(`foo=`, 11, `bar-=`, 22)) + + UPDATE.data allows to pass in plain data payloads, e.g. as obtained from REST clients. + The passed in object can be modified subsequently, e.g. by adding or modifying values + before the query is finally executed. + */ + test('with + data', () => { + if (cds.version < '4.1.0') return + const o = {} + const q = UPDATE(Foo).data(o).with(`bar-=`, 22) + o.foo = 11 + expect(q) + .to.eql(UPDATE(Foo).with(`foo=`, 11, `bar-=`, 22)) .to.eql(UPDATE(Foo).with({ foo: 11, bar: { '-=': 22 } })) .to.eql({ UPDATE: { entity: 'Foo', + data: { foo: 11 }, with: { - foo: { val: 11 }, bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] }, }, }, }) // some more - // expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({ - // UPDATE: { - // entity: 'Foo', - // with: { - // bar: { func: 'coalesce', args: [{ ref: ['x'] }, { ref: ['y'] }] }, - // car: { val: "foo's bar, car" }, - // }, - // }, - // }) - }) - - /* - UPDATE.data allows to pass in plain data payloads, e.g. as obtained from REST clients. - The passed in object can be modified subsequently, e.g. by adding or modifying values - before the query is finally executed. - */ - test('data', () => { - const o = {} - const q = UPDATE(Foo).data(o).with(`bar-=`, 22) - o.foo = 11 - expect(q).to.eql({ + expect(UPDATE(Foo).with(`bar = coalesce(x,y), car = 'foo''s bar, car'`)).to.eql({ UPDATE: { entity: 'Foo', - data: { foo: 11 }, + data: { + car: "foo's bar, car", + }, with: { - bar: { xpr: [{ ref: ['bar'] }, '-', { val: 22 }] }, + bar: { func: 'coalesce', args: [{ ref: ['x'] }, { ref: ['y'] }] }, }, }, }) From 6ccecfecaea03d48605abe41c6fbfe70eba61cf6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 17 Jul 2020 16:04:03 +0200 Subject: [PATCH 11/19] Doing bindings in .env --- reviewed/.env | 1 + reviewed/package.json | 3 --- reviews/.env | 1 + reviews/package.json | 3 --- 4 files changed, 2 insertions(+), 6 deletions(-) create mode 100644 reviewed/.env diff --git a/reviewed/.env b/reviewed/.env new file mode 100644 index 00000000..24a7ee31 --- /dev/null +++ b/reviewed/.env @@ -0,0 +1 @@ +cds.requires.messaging.kind = file-based-messaging \ No newline at end of file diff --git a/reviewed/package.json b/reviewed/package.json index 1a11aed8..8bd2d2ff 100644 --- a/reviewed/package.json +++ b/reviewed/package.json @@ -14,9 +14,6 @@ }, "ReviewsService": { "kind": "odata", "model": "@capire/reviews" - }, - "messaging": { - "kind": "file-based-messaging" } } } diff --git a/reviews/.env b/reviews/.env index 378d6075..8184d48d 100644 --- a/reviews/.env +++ b/reviews/.env @@ -1 +1,2 @@ +cds.requires.messaging.kind = file-based-messaging PORT = 5005 \ No newline at end of file diff --git a/reviews/package.json b/reviews/package.json index b974df69..373ba66c 100644 --- a/reviews/package.json +++ b/reviews/package.json @@ -18,9 +18,6 @@ "requires": { "db": { "kind": "sql" - }, - "messaging": { - "kind": "file-based-messaging" } } } From aaac6cc67823cbabde3bc575587931a38bef9928 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Jul 2020 01:24:39 +0200 Subject: [PATCH 12/19] Secured cwd in test --- test/consuming-services.test.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 6a5b4174..1158452d 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,9 +1,11 @@ const { expect } = require('./capire') const cds = require('@sap/cds') +const cwd = process.cwd() describe('Consuming Services locally', () => { // before('bootstrap db and services', async () => { + process.chdir(__dirname) const model = await cds.load(['@capire/bookshop', '@capire/common']) await cds.deploy(model).to('sqlite::memory:') const { AdminService } = await cds.serve('AdminService').from(model) @@ -12,6 +14,8 @@ describe('Consuming Services locally', () => { expect(Authors).not.to.be.undefined }) + after(()=> process.chdir(cwd)) + it('bootrapped the database successfully', ()=>{}) it('supports targets as strings or reflected defs', async () => { From 9a9b7aeb864284c41071fc1a14fa8bd776a49aa5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Jul 2020 01:56:56 +0200 Subject: [PATCH 13/19] Fxed cwd in tests --- test/consuming-services.test.js | 6 +++--- test/custom-handlers.test.js | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/test/consuming-services.test.js b/test/consuming-services.test.js index 1158452d..54a8410b 100644 --- a/test/consuming-services.test.js +++ b/test/consuming-services.test.js @@ -1,11 +1,13 @@ const { expect } = require('./capire') const cds = require('@sap/cds') + const cwd = process.cwd() +before (()=> process.chdir(__dirname)) +after(()=> process.chdir(cwd)) describe('Consuming Services locally', () => { // before('bootstrap db and services', async () => { - process.chdir(__dirname) const model = await cds.load(['@capire/bookshop', '@capire/common']) await cds.deploy(model).to('sqlite::memory:') const { AdminService } = await cds.serve('AdminService').from(model) @@ -14,8 +16,6 @@ describe('Consuming Services locally', () => { expect(Authors).not.to.be.undefined }) - after(()=> process.chdir(cwd)) - it('bootrapped the database successfully', ()=>{}) it('supports targets as strings or reflected defs', async () => { diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index 5efec938..4fa4fc94 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -1,3 +1,7 @@ +const cwd = process.cwd() +before (()=> process.chdir(__dirname)) +after(()=> process.chdir(cwd)) + describe('Custom Handlers', () => { const { GET, POST, expect } = require('./capire').launch('bookshop') From 74ee6f34e400c5c820db8a5d6590e6ae3435cabc Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 23 Jul 2020 02:00:34 +0200 Subject: [PATCH 14/19] Fixed jest mocha --- test/custom-handlers.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/custom-handlers.test.js b/test/custom-handlers.test.js index 4fa4fc94..8c2f95d3 100644 --- a/test/custom-handlers.test.js +++ b/test/custom-handlers.test.js @@ -1,6 +1,11 @@ const cwd = process.cwd() +const is_jest = !!global.test +if (is_jest) { // it's jest + global.before = (msg,fn) => global.beforeAll(fn||msg) + global.after = (msg,fn) => global.afterAll(fn||msg) +} before (()=> process.chdir(__dirname)) -after(()=> process.chdir(cwd)) +after (()=> process.chdir(cwd)) describe('Custom Handlers', () => { const { GET, POST, expect } = require('./capire').launch('bookshop') From 4b78a8b63778c6dc6ceb7410ed8e387f1f92d285 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Fri, 31 Jul 2020 12:36:11 +0200 Subject: [PATCH 15/19] Do no longer use run blocks - removed in cds 4 --- orders/srv/orders-service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/orders/srv/orders-service.js b/orders/srv/orders-service.js index 55d0e1ba..ac92a56e 100644 --- a/orders/srv/orders-service.js +++ b/orders/srv/orders-service.js @@ -7,7 +7,7 @@ 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 => + return cds.transaction(req) .run (OrderItems.map (order => UPDATE (Books) .where ('ID =', order.book_ID) .and ('stock >=', order.amount) .set ('stock -=', order.amount) From ada05cf2790558a8a3c33aab281c3d2fb56b5b1d Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Fri, 31 Jul 2020 16:25:10 +0200 Subject: [PATCH 16/19] Cosmetics --- orders/srv/orders-service.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/orders/srv/orders-service.js b/orders/srv/orders-service.js index ac92a56e..bc401fd4 100644 --- a/orders/srv/orders-service.js +++ b/orders/srv/orders-service.js @@ -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}` ) })) }) From 1b69064752b2515fb5984f81cf1da6c83ed7d328 Mon Sep 17 00:00:00 2001 From: Christian Georgi Date: Fri, 31 Jul 2020 16:44:05 +0200 Subject: [PATCH 17/19] Make cuid.ID Core.Computed for now + TODO to check w/ Fiori --- orders/db/schema.cds | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/orders/db/schema.cds b/orders/db/schema.cds index 048aba28..f72f737a 100644 --- a/orders/db/schema.cds +++ b/orders/db/schema.cds @@ -14,3 +14,7 @@ entity OrderItems : cuid { amount : Integer; netAmount : Decimal(9,2); } + +// Have IDs auto-computed. TODO revisit w/ Fiori how long this is needed +// see https://answers.sap.com/questions/13091274/sample-fiori-app-creating-a-new-order-shows-a-popu.html +annotate cuid with { ID @Core.Computed; } From fa7cff412398826c480a7a5eeb91a3e2255186a3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 1 Aug 2020 14:44:13 +0200 Subject: [PATCH 18/19] Pinning Fiori to last-known-good --- fiori/app/fiori.html | 3 ++- orders/db/schema.cds | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/fiori/app/fiori.html b/fiori/app/fiori.html index 26182c12..aec60a55 100644 --- a/fiori/app/fiori.html +++ b/fiori/app/fiori.html @@ -40,7 +40,8 @@ -