From 37e04830d0c43085d10052604ab603313bf81c56 Mon Sep 17 00:00:00 2001 From: i332371 Date: Thu, 15 Feb 2024 22:03:58 +0530 Subject: [PATCH 1/7] copy scripts & tests * Copy scripts for additional xmpls * removed test in xmpls, new tests will be added * minor fixes in xmpls --- package.json | 3 + test/basics.test.js | 2 +- test/drafts.test.js | 2 +- xmpls/messaging/app/incidents/field.cds | 2 +- xmpls/messaging/package.json | 8 +- xmpls/messaging/srv/services.js | 2 +- xmpls/messaging/tests/test.js | 113 ------------------------ xmpls/remote-service/package.json | 6 +- xmpls/remote-service/srv/services.js | 2 +- xmpls/remote-service/tests/test.js | 113 ------------------------ 10 files changed, 20 insertions(+), 233 deletions(-) delete mode 100644 xmpls/messaging/tests/test.js delete mode 100644 xmpls/remote-service/tests/test.js diff --git a/package.json b/package.json index 72b7db1..320e3d6 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,9 @@ "clone-add-attachments": "git clone https://github.com/cap-js/attachments.git && cp -r attachments/xmpl/db . && cp -r attachments/xmpl/app . && npm add https://github.com/cap-js/attachments.git", "add-notifications": "npm add @cap-js/notifications && cp xmpls/alert-notifications.js ./srv && cp xmpls/notification-types.json ./srv", "add-audit-log": "npm add @cap-js/audit-logging && cp xmpls/data-privacy.cds ./srv", + "add-remote-service": "cp -r xmpls/remote-service/ .", + "add-messaging": "cp -r xmpls/messaging/ .", + "add-all-xmpls": "npm run add-messaging && npm run add-change-tracking && npm run add-audit-log", "reset": "read -p 'This will irreversibly reset your working directory including ALL files in this git repo. Continue?' -n 1 -r && echo && if [[ $REPLY =~ ^[Yy]$ ]]; then git clean -fd && git reset --hard && npm i; fi" }, "jest": { diff --git a/test/basics.test.js b/test/basics.test.js index 5dd0e91..99eaf63 100644 --- a/test/basics.test.js +++ b/test/basics.test.js @@ -1,5 +1,5 @@ const cds = require('@sap/cds/lib') -const { GET, expect, axios } = cds.test(__dirname + '/..') +const { GET, expect, axios } = cds.test(__dirname + '/..', '--with-mocks') axios.defaults.auth = { username: 'alice' } diff --git a/test/drafts.test.js b/test/drafts.test.js index 82d4c21..68dc32d 100644 --- a/test/drafts.test.js +++ b/test/drafts.test.js @@ -1,5 +1,5 @@ const cds = require('@sap/cds/lib') -const { GET, POST, DELETE, PATCH, expect, axios } = cds.test(__dirname + '/..') +const { GET, POST, DELETE, PATCH, expect, axios } = cds.test(__dirname + '/..', '--with-mocks') axios.defaults.auth = { username: 'alice' } diff --git a/xmpls/messaging/app/incidents/field.cds b/xmpls/messaging/app/incidents/field.cds index 35529eb..9368152 100644 --- a/xmpls/messaging/app/incidents/field.cds +++ b/xmpls/messaging/app/incidents/field.cds @@ -1,4 +1,4 @@ -using ProcessorService as service from '../../srv/processor-service'; +using ProcessorService as service from '../../srv/services.cds'; using from './annotations.cds'; annotate service.Incidents with @( /*adding email to the object page enables users to view the diff --git a/xmpls/messaging/package.json b/xmpls/messaging/package.json index 0d44335..1dbf0cf 100644 --- a/xmpls/messaging/package.json +++ b/xmpls/messaging/package.json @@ -27,12 +27,18 @@ "scripts": { "watch": "cds watch", "start": "cds-serve", - "test": "npx jest --silent" + "test": "npx jest --silent", + "reset": "read -p 'This will irreversibly reset your working directory including ALL files in this git repo. Continue?' -n 1 -r && echo && if [[ $REPLY =~ ^[Yy]$ ]]; then git clean -fd && git reset --hard && npm i; fi" }, "private": true, "sapux": [ "app/incidents" ], + "jest": { + "modulePathIgnorePatterns": [ + "/xmpls/" + ] + }, "cds": { "requires": { "incidents-app": { diff --git a/xmpls/messaging/srv/services.js b/xmpls/messaging/srv/services.js index 2bfeb2e..e170a96 100644 --- a/xmpls/messaging/srv/services.js +++ b/xmpls/messaging/srv/services.js @@ -30,8 +30,8 @@ class ProcessorService extends cds.ApplicationService { address.email(emails => { emails('*')}) }).where({BusinessPartner: Id})); - customer.email = customer.email[0]?.email if(customer){ + customer.email = customer.email[0]?.email const result= await cds.run(UPDATE(Customers).where({ID: customer.ID}).set({email:customer.email})); console.log("result",result); } diff --git a/xmpls/messaging/tests/test.js b/xmpls/messaging/tests/test.js deleted file mode 100644 index 6192e29..0000000 --- a/xmpls/messaging/tests/test.js +++ /dev/null @@ -1,113 +0,0 @@ -const cds = require('@sap/cds/lib'); -const { default: axios } = require('axios'); -const { GET, POST, DELETE, PATCH, expect } = cds.test(__dirname + '../../', '--with-mocks'); - -axios.defaults.auth = { username: "incident.support@tester.sap.com", password: "initial" } - -jest.setTimeout(11111) - -describe('Test The GET Endpoints', () => { - it('Should check Processor Service', async () => { - const processorService = await cds.connect.to('ProcessorService'); - const { Incidents } = processorService.entities; - expect(await SELECT.from(Incidents)).to.have.length(4); - }); - - it('Should check Customers', async () => { - const processorService = await cds.connect.to('ProcessorService'); - const { Customers } = processorService.entities; - expect(await SELECT.from(Customers)).to.have.length(3); - }); - - it('Test Expand Entity Endpoint', async () => { - const { data } = await GET`/odata/v4/processor/Customers?$select=firstName&$expand=incidents`; - expect(data).to.be.an('object'); - }); -}); - -describe('Draft Choreography APIs', () => { - let draftId,incidentId; - - it('Create an incident ', async () => { - const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, { - title: 'Urgent attention required !', - status_code: 'N', - }); - draftId = data.ID; - expect(status).to.equal(201); - expect(statusText).to.equal('Created'); - }); - - it('+ Activate the draft & check Urgency code as H using custom logic', async () => { - const response = await POST( - `/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - expect(response.status).to.eql(201); - expect(response.data.urgency_code).to.eql('H'); - }); - - it('+ Test the incident status', async () => { - const { status, data: { status_code, ID } } = await GET(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`); - incidentId = ID; - expect(status).to.eql(200); - expect(status_code).to.eql('N'); - }); - - describe('Close Incident and Open it again to check Custom logic',()=>{ - - it(`Should Close the Incident-${draftId}`, async ()=>{ - const {status} = await POST(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`, - { - "PreserveChanges": true - }); - expect(status).to.equal(201); - }); - - it(`Should Close the Incident-${draftId}`, async ()=>{ - const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`,{status_code: 'C'}); - expect(status).to.equal(200); - }); - it('+ Activate the draft & check Status code as C using custom logic', async () => { - const response = await POST( - `/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - expect(response.status).to.eql(200); - }); - - it('+ Test the incident status to be closed', async () => { - const { status, data: { status_code } } = await GET(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)`); - expect(status).to.eql(200); - expect(status_code).to.eql('C'); - }); - describe('should fail to re-open closed incident', ()=>{ - - it(`Should Open Closed Incident-${draftId}`, async ()=>{ - const {status} = await POST(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`, - { - "PreserveChanges": true - }); - expect(status).to.equal(201); - }); - - it(`Should re-open the Incident-${draftId} but fail`, async ()=>{ - const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`,{status_code: 'N'}); - expect(status).to.equal(200); - }); - it(' `Should fail to activate draft trying to re-open the incidentt', async () => { - try{ - const response = await POST( - `/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - }catch(error){ - expect(error.response.status).to.eql(500); - expect(error.response.data.error.message).to.include(`Can't modify a closed incident`); - } - }); - }) - }); - - it('- Delete the Incident', async () => { - const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`); - expect(response.status).to.eql(204); - }); -}); \ No newline at end of file diff --git a/xmpls/remote-service/package.json b/xmpls/remote-service/package.json index 9fa9deb..c8fbde5 100644 --- a/xmpls/remote-service/package.json +++ b/xmpls/remote-service/package.json @@ -26,12 +26,16 @@ "scripts": { "watch": "cds watch", "start": "cds-serve", - "test": "npx jest --silent" + "test": "npx jest --silent", + "reset": "read -p 'This will irreversibly reset your working directory including ALL files in this git repo. Continue?' -n 1 -r && echo && if [[ $REPLY =~ ^[Yy]$ ]]; then git clean -fd && git reset --hard && npm i; fi" }, "private": true, "sapux": [ "app/incidents" ], + "jest": { + "modulePathIgnorePatterns": ["/xmpls/"] + }, "cds": { "requires": { "incidents-app": { diff --git a/xmpls/remote-service/srv/services.js b/xmpls/remote-service/srv/services.js index cdba468..bddb5d4 100644 --- a/xmpls/remote-service/srv/services.js +++ b/xmpls/remote-service/srv/services.js @@ -51,7 +51,7 @@ class ProcessorService extends cds.ApplicationService { const top = parseInt(req._queryOptions?.$top) || 100; const skip = parseInt(req._queryOptions?.$skip) || 0; - const { BusinessPartner } = this.entities; + const { BusinessPartner } = this.remoteService.entities; // Expands are required as the runtime does not support path expressions for remote services let result = await this.S4bupa.run(SELECT.from(BusinessPartner, bp => { diff --git a/xmpls/remote-service/tests/test.js b/xmpls/remote-service/tests/test.js deleted file mode 100644 index 6192e29..0000000 --- a/xmpls/remote-service/tests/test.js +++ /dev/null @@ -1,113 +0,0 @@ -const cds = require('@sap/cds/lib'); -const { default: axios } = require('axios'); -const { GET, POST, DELETE, PATCH, expect } = cds.test(__dirname + '../../', '--with-mocks'); - -axios.defaults.auth = { username: "incident.support@tester.sap.com", password: "initial" } - -jest.setTimeout(11111) - -describe('Test The GET Endpoints', () => { - it('Should check Processor Service', async () => { - const processorService = await cds.connect.to('ProcessorService'); - const { Incidents } = processorService.entities; - expect(await SELECT.from(Incidents)).to.have.length(4); - }); - - it('Should check Customers', async () => { - const processorService = await cds.connect.to('ProcessorService'); - const { Customers } = processorService.entities; - expect(await SELECT.from(Customers)).to.have.length(3); - }); - - it('Test Expand Entity Endpoint', async () => { - const { data } = await GET`/odata/v4/processor/Customers?$select=firstName&$expand=incidents`; - expect(data).to.be.an('object'); - }); -}); - -describe('Draft Choreography APIs', () => { - let draftId,incidentId; - - it('Create an incident ', async () => { - const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, { - title: 'Urgent attention required !', - status_code: 'N', - }); - draftId = data.ID; - expect(status).to.equal(201); - expect(statusText).to.equal('Created'); - }); - - it('+ Activate the draft & check Urgency code as H using custom logic', async () => { - const response = await POST( - `/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - expect(response.status).to.eql(201); - expect(response.data.urgency_code).to.eql('H'); - }); - - it('+ Test the incident status', async () => { - const { status, data: { status_code, ID } } = await GET(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`); - incidentId = ID; - expect(status).to.eql(200); - expect(status_code).to.eql('N'); - }); - - describe('Close Incident and Open it again to check Custom logic',()=>{ - - it(`Should Close the Incident-${draftId}`, async ()=>{ - const {status} = await POST(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`, - { - "PreserveChanges": true - }); - expect(status).to.equal(201); - }); - - it(`Should Close the Incident-${draftId}`, async ()=>{ - const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`,{status_code: 'C'}); - expect(status).to.equal(200); - }); - it('+ Activate the draft & check Status code as C using custom logic', async () => { - const response = await POST( - `/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - expect(response.status).to.eql(200); - }); - - it('+ Test the incident status to be closed', async () => { - const { status, data: { status_code } } = await GET(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)`); - expect(status).to.eql(200); - expect(status_code).to.eql('C'); - }); - describe('should fail to re-open closed incident', ()=>{ - - it(`Should Open Closed Incident-${draftId}`, async ()=>{ - const {status} = await POST(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=true)/ProcessorService.draftEdit`, - { - "PreserveChanges": true - }); - expect(status).to.equal(201); - }); - - it(`Should re-open the Incident-${draftId} but fail`, async ()=>{ - const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)`,{status_code: 'N'}); - expect(status).to.equal(200); - }); - it(' `Should fail to activate draft trying to re-open the incidentt', async () => { - try{ - const response = await POST( - `/odata/v4/processor/Incidents(ID=${incidentId},IsActiveEntity=false)/ProcessorService.draftActivate` - ); - }catch(error){ - expect(error.response.status).to.eql(500); - expect(error.response.data.error.message).to.include(`Can't modify a closed incident`); - } - }); - }) - }); - - it('- Delete the Incident', async () => { - const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`); - expect(response.status).to.eql(204); - }); -}); \ No newline at end of file From 6fd38b1dddb40c062da05e86300f9c44f51bba01 Mon Sep 17 00:00:00 2001 From: i332371 Date: Thu, 15 Feb 2024 22:11:18 +0530 Subject: [PATCH 2/7] npm script to add all xmpls --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 320e3d6..e47b5a8 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "add-audit-log": "npm add @cap-js/audit-logging && cp xmpls/data-privacy.cds ./srv", "add-remote-service": "cp -r xmpls/remote-service/ .", "add-messaging": "cp -r xmpls/messaging/ .", - "add-all-xmpls": "npm run add-messaging && npm run add-change-tracking && npm run add-audit-log", + "add-all-xmpls": "npm run add-change-tracking && npm run add-audit-log && npm run add-messaging", "reset": "read -p 'This will irreversibly reset your working directory including ALL files in this git repo. Continue?' -n 1 -r && echo && if [[ $REPLY =~ ^[Yy]$ ]]; then git clean -fd && git reset --hard && npm i; fi" }, "jest": { From 1db02bc6ea45a1c5883250464b8b67c23e5269e0 Mon Sep 17 00:00:00 2001 From: Gopal Anand <32189444+gopalanand333@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:43:42 +0530 Subject: [PATCH 3/7] update ui5 version (#46) * update ui5 version --- app/incidents/webapp/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/incidents/webapp/index.html b/app/incidents/webapp/index.html index c260df4..560c132 100644 --- a/app/incidents/webapp/index.html +++ b/app/incidents/webapp/index.html @@ -12,7 +12,7 @@