From 37e04830d0c43085d10052604ab603313bf81c56 Mon Sep 17 00:00:00 2001 From: i332371 Date: Thu, 15 Feb 2024 22:03:58 +0530 Subject: [PATCH 1/6] 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/6] 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 55a491c3d05ff34373a7e30c9a2ae6312f1a0855 Mon Sep 17 00:00:00 2001 From: i332371 Date: Fri, 16 Feb 2024 16:37:20 +0530 Subject: [PATCH 3/6] additional tests for xmpls --- xmpls/audit-log.test.js | 62 ++++++++ xmpls/change-tracking.test.js | 133 ++++++++++++++++++ xmpls/messaging/test/messaging.test.js | 106 ++++++++++++++ .../test/remote-service.test.js | 91 ++++++++++++ 4 files changed, 392 insertions(+) create mode 100644 xmpls/audit-log.test.js create mode 100644 xmpls/change-tracking.test.js create mode 100644 xmpls/messaging/test/messaging.test.js create mode 100644 xmpls/remote-service/test/remote-service.test.js diff --git a/xmpls/audit-log.test.js b/xmpls/audit-log.test.js new file mode 100644 index 0000000..3de685c --- /dev/null +++ b/xmpls/audit-log.test.js @@ -0,0 +1,62 @@ +const cds = require("@sap/cds"); +const { GET, POST, PATCH, DELETE, expect, axios, assert } = cds.test(__dirname + '/..', '--with-mocks') + +axios.defaults.auth = { username: "alice" }; +describe("Integration Test for AuditLog", () => { + let customerID,audit; + beforeAll(async () => { + audit = await cds.connect.to('audit-log') + }); + + it("Should return list of Customers", async () => { + const response = await GET("/odata/v4/processor/Customers"); + + audit.on('SensitiveDataRead', function (req) { + const { event, data } = req + assert.ok(event.includes("SensitiveDataRead")) + }) + expect(response.status).to.eql(200); + }); + + + it("Should return list of Customers data by explicitly selecting the fields", async () => { + const response = await GET("/odata/v4/processor/Customers?$select=name"); + expect(response.status).to.eql(200); + }); + + + it('Creating a customer with personal data', async () => { + const response = await POST(`/odata/v4/admin/Customers`, { + ID: "{{$guid}}", + firstName: "Bob", + lastName: "Builder", + email: "bob.builder@example.com" + }); + audit.on('PersonalDataModified', function (req) { + const { event, data } = req + assert.ok(event.includes("PersonalDataModified")) + }) + customerID = response.data.ID; + expect(response.status).to.equal(201); + }); + + + it('Updating a customer with personal data details', async () => { + const audit = await cds.connect.to('audit-log') + audit.on('PersonalDataModified', function (req) { + const { event, data } = req + assert.ok(event.includes("PersonalDataModified")) + }) + const response = await PATCH(`/odata/v4/admin/Customers('${customerID}')`, { + "addresses": [ + { + "city": "Walldorf", + "postCode": "69190", + "streetAddress": "Dietmar-Hopp-Allee 16" + } + ] + }); + expect(response.status).to.equal(200); + }); + +}); diff --git a/xmpls/change-tracking.test.js b/xmpls/change-tracking.test.js new file mode 100644 index 0000000..89bf809 --- /dev/null +++ b/xmpls/change-tracking.test.js @@ -0,0 +1,133 @@ +const cds = require("@sap/cds"); +const { GET, POST, PATCH, DELETE , expect, axios} = cds.test(__dirname + '/..', '--with-mocks') + +describe("Integration Test for ChangeTracking", () => { + let draftId,incidentId; + axios.defaults.auth = { username: "alice" }; + let processorService = null; + let ChangeView = null; + beforeAll(async () => { + processorService = await cds.connect.to('ProcessorService'); + ChangeView = processorService.entities.ChangeView; + }); + it('Create an incident ', async () => { + const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, { + title: 'Urgent attention required !', + status_code: 'N', + "customer": {ID:"1004100"} + }); + 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'); + }); + + it('+ Test the title detail in ChangeView', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + const incidentChanges = await SELECT.from(ChangeView).where({ + entity: "sap.capire.incidents.Incidents", + attribute: "title", + }) + expect(incidentChanges.length).to.equal(1); + const incidentChange = incidentChanges[0]; + expect(incidentChange.entityKey).to.equal(draftId); + expect(incidentChange.attribute).to.equal("title"); + expect(incidentChange.modification).to.equal("create"); + expect(incidentChange.valueChangedFrom).to.equal(""); + expect(incidentChange.valueChangedTo).to.equal("Urgent attention required !"); + }); + + it('+ Test the status detail in ChangeView', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + const incidentChanges = await SELECT.from(ChangeView).where({ + entity: "sap.capire.incidents.Incidents", + attribute: "status", + }) + expect(incidentChanges.length).to.equal(1); + const incidentChange = incidentChanges[0]; + expect(incidentChange.entityKey).to.equal(draftId); + expect(incidentChange.attribute).to.equal("status"); + expect(incidentChange.modification).to.equal("create"); + expect(incidentChange.valueChangedFrom).to.equal(""); + expect(incidentChange.valueChangedTo).to.equal("N"); + }); + + it('+ Test the customer detail in ChangeView', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + const incidentChanges = await SELECT.from(ChangeView).where({ + entity: "sap.capire.incidents.Incidents", + attribute: "customer", + }) + expect(incidentChanges.length).to.equal(1); + const incidentChange = incidentChanges[0]; + expect(incidentChange.entityKey).to.equal(draftId); + expect(incidentChange.attribute).to.equal("customer"); + expect(incidentChange.modification).to.equal("create"); + expect(incidentChange.valueChangedFrom).to.equal(""); + expect(incidentChange.valueChangedTo).to.equal("Sunny Sunshine"); + }); + + describe("Test Changes for Update Incident", () => { + it(`Should Close the Incident-${draftId}`, async ()=>{ + const {status} = await POST(`/odata/v4/processor/Incidents(ID=${draftId},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=${draftId},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=${draftId},IsActiveEntity=false)/ProcessorService.draftActivate` + ); + expect(response.status).to.eql(200); + }); + it('+ Test the status detail in ChangeView', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + const incidentChanges = await SELECT.from(ChangeView).where({ + entity: "sap.capire.incidents.Incidents", + attribute: "status", + modification: 'update', + }) + expect(incidentChanges.length).to.equal(1); + const incidentChange = incidentChanges[0]; + expect(incidentChange.entityKey).to.equal(draftId); + expect(incidentChange.attribute).to.equal("status"); + expect(incidentChange.modification).to.equal("update"); + expect(incidentChange.valueChangedFrom).to.equal("N"); + expect(incidentChange.valueChangedTo).to.equal("C"); + }); + }); + + describe("Test Changes for Delete Incident", () => { + it('- Delete the Incident', async () => { + const response = await DELETE(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)`); + expect(response.status).to.eql(204); + }); + + it('+ Test the status detail in ChangeView', async () => { + const incidentChanges = await SELECT.from(ChangeView).where({ + entity: "sap.capire.incidents.Incidents", + attribute: "status", + }) + expect(incidentChanges.length).to.equal(0); + }); + }); +}); diff --git a/xmpls/messaging/test/messaging.test.js b/xmpls/messaging/test/messaging.test.js new file mode 100644 index 0000000..3e8dfb2 --- /dev/null +++ b/xmpls/messaging/test/messaging.test.js @@ -0,0 +1,106 @@ +const cds = require("@sap/cds"); +const { GET, POST, PATCH, DELETE, expect, axios } = cds.test(__dirname + '/..', '--with-mocks') + +describe("Integration Test for Eventing", () => { + let draftId,incidentId; + axios.defaults.auth = { username: "alice" }; + describe("GET should return 200", () => { + + it("Should return list of Business Partners", async () => { + const response = await GET("/odata/v4/api-business-partner/A_BusinessPartner"); + expect(response.status).to.eql(200); + }); + + it("Should return list of Business Partners Address", async () => { + const response = await GET("/odata/v4/api-business-partner/A_BusinessPartnerAddress"); + expect(response.status).to.eql(200); + }); + it("Should return list of Business Partners Email Address", async () => { + const response = await GET("/odata/v4/api-business-partner/A_AddressEmailAddress"); + expect(response.status).to.eql(200); + }); + it("Should return list of Business Partners Address PhoneNumber", async () => { + const response = await GET("/odata/v4/api-business-partner/A_AddressPhoneNumber"); + expect(response.status).to.eql(200); + }); + }); + + describe('Draft Choreography APIs', () => { + it('Create an incident ', async () => { + const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, { + title: 'Urgent attention required !', + status_code: 'N', + "customer": {ID:"1004100"} + }); + 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 customer detail', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + expect(response.status).to.eql(200); + expect(response.data.value).to.exist; + expect(response.data.value[0]).to.contains({ + "customer_ID": "1004100" + }); + incidentId = response.data.ID; + }); + + describe("Create annd Update Business Partner", () => { + it("Update Business Partner", async () => { + const response = await PATCH( + `/odata/v4/api-business-partner/A_BusinessPartner('1004100')`, + { + to_BusinessPartnerAddress: [{ + AddressID: "457", + to_EmailAddress:[{ + AddressID: "457", + Person: "johnson", + OrdinalNumber: "334", + EmailAddress: "sunny@test.com" + }] + }] + } + ); + expect(response.status).to.eql(200); + }); + describe("Verify the updated Business Partner", () => { + it("Verify the Address of Business Partner", async () => { + const response = await GET(`/odata/v4/api-business-partner/A_BusinessPartnerAddress?$filter=BusinessPartner eq '1004100'`); + expect(response.status).to.eql(200); + expect(response.data.value).to.exist; + expect(response.data.value[0]).to.contains({ + AddressID: "457", + }); + }); + + it("Verify the Email address of Business Partner", async () => { + const response = await GET(`/odata/v4/api-business-partner/A_AddressEmailAddress?$filter=AddressID eq '457'`); + expect(response.status).to.eql(200); + expect(response.data.value).to.exist; + expect(response.data.value[0]).to.contains({ + AddressID: "457", + Person: "johnson", + OrdinalNumber: "334", + EmailAddress: "sunny@test.com" + }); + }); + }); + }); + + it(`Should Close the Incident-${draftId}`, async ()=>{ + const {status} = await POST(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)/ProcessorService.draftEdit`, + { + "PreserveChanges": true + }); + expect(status).to.equal(201); + }); + }); +}); diff --git a/xmpls/remote-service/test/remote-service.test.js b/xmpls/remote-service/test/remote-service.test.js new file mode 100644 index 0000000..e83fe42 --- /dev/null +++ b/xmpls/remote-service/test/remote-service.test.js @@ -0,0 +1,91 @@ +const cds = require("@sap/cds"); +const { GET, POST, PATCH, DELETE, expect, axios } = cds.test(__dirname + '../../', '--with-mocks'); +axios.defaults.auth = { username: "alice" }; + +describe("Integration Test for Remote Service", () => { + let draftId,incidentId; + describe("Test the BusinessPartner GET Endpoints", () => { + + it("Should return list of Business Partners", async () => { + const response = await GET("/odata/v4/api-business-partner/A_BusinessPartner"); + expect(response.status).to.eql(200); + }); + + it("Should return list of Business Partners Address", async () => { + const response = await GET("/odata/v4/api-business-partner/A_BusinessPartnerAddress"); + expect(response.status).to.eql(200); + }); + it("Should return list of Business Partners Email Address", async () => { + const response = await GET("/odata/v4/api-business-partner/A_AddressEmailAddress"); + expect(response.status).to.eql(200); + }); + it("Should return list of Business Partners Address PhoneNumber", async () => { + const response = await GET("/odata/v4/api-business-partner/A_AddressPhoneNumber"); + expect(response.status).to.eql(200); + }); + }); + + describe('Draft Choreography APIs', () => { + it('Create an incident ', async () => { + const { status, statusText, data } = await POST(`/odata/v4/processor/Incidents`, { + title: 'Urgent attention required !', + status_code: 'N', + "customer": {ID:"1004100"} + }); + 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 customer detail', async () => { + const response = await GET(`/odata/v4/processor/Incidents?$filter=ID eq ${draftId}`); + //incidentId = ID; + expect(response.status).to.eql(200); + expect(response.data.value).to.exist; + expect(response.data.value[0]).to.contains({ + "customer_ID": "1004100" + }); + incidentId = response.data.ID; + }); + + describe("Create annd Update Business Partner", () => { + it("Creates a new Business Partner", async () => { + const payload = { + BusinessPartner: "17100015", + BusinessPartnerIsBlocked: true, + BusinessPartnerFullName: "John Doee", + }; + const response = await POST( + "/odata/v4/api-business-partner/A_BusinessPartner", + payload + ); + expect(response.status).to.eql(201); + }); + it("Update Business Partner", async () => { + const response = await PATCH( + `/odata/v4/api-business-partner/A_BusinessPartner('17100015')`, + {BusinessPartnerIsBlocked: false} + ); + expect(response.status).to.eql(200); + }); + }); + + it(`Should Close the Incident-${draftId}`, async ()=>{ + const {status} = await POST(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=true)/ProcessorService.draftEdit`, + { + "PreserveChanges": true + }); + expect(status).to.equal(201); + }); + it(`Update Business Partner details of the Incident`, async ()=>{ + const {status } = await PATCH(`/odata/v4/processor/Incidents(ID=${draftId},IsActiveEntity=false)`,{customer_ID: '17100015'}); + expect(status).to.equal(200); + }); + }); +}); From 86584fd234be6b01f140b33469ea8b86379957e8 Mon Sep 17 00:00:00 2001 From: i332371 Date: Fri, 16 Feb 2024 16:39:12 +0530 Subject: [PATCH 4/6] copy scripts for tests --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e47b5a8..b5bc230 100644 --- a/package.json +++ b/package.json @@ -27,12 +27,12 @@ "watch": "cds watch", "start": "cds-serve", "test": "npx jest --silent", - "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv", + "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./srv", "add-telemetry": "npm add @cap-js/telemetry", "add-attachments": "npm add @cap-js/attachments && cp xmpls/attachments.cds ./srv && cp -r xmpls/content ./db/data/content", "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-audit-log": "npm add @cap-js/audit-logging && cp xmpls/data-privacy.cds ./srv && cp xmpls/audit-log.test.js ./test", "add-remote-service": "cp -r xmpls/remote-service/ .", "add-messaging": "cp -r xmpls/messaging/ .", "add-all-xmpls": "npm run add-change-tracking && npm run add-audit-log && npm run add-messaging", From 1bc77396b1434ef6941d4bed0c981b37b8858e20 Mon Sep 17 00:00:00 2001 From: i332371 Date: Fri, 16 Feb 2024 16:44:00 +0530 Subject: [PATCH 5/6] copy test scripts --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b5bc230..580c5db 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "watch": "cds watch", "start": "cds-serve", "test": "npx jest --silent", - "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./srv", + "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./test", "add-telemetry": "npm add @cap-js/telemetry", "add-attachments": "npm add @cap-js/attachments && cp xmpls/attachments.cds ./srv && cp -r xmpls/content ./db/data/content", "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", From 8d1fc9994654265f6c26e686beef74cade78fac3 Mon Sep 17 00:00:00 2001 From: i332371 Date: Fri, 16 Feb 2024 17:05:59 +0530 Subject: [PATCH 6/6] scripts --- package.json | 2 +- xmpls/messaging/package.json | 12 +++++++++++- xmpls/remote-service/package.json | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 580c5db..2e9060e 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 && cp xmpls/audit-log.test.js ./test", "add-remote-service": "cp -r xmpls/remote-service/ .", "add-messaging": "cp -r xmpls/messaging/ .", - "add-all-xmpls": "npm run add-change-tracking && npm run add-audit-log && npm run add-messaging", + "add-all-xmpls": "npm run add-remote-service && 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/xmpls/messaging/package.json b/xmpls/messaging/package.json index 1dbf0cf..8a1299c 100644 --- a/xmpls/messaging/package.json +++ b/xmpls/messaging/package.json @@ -28,6 +28,15 @@ "watch": "cds watch", "start": "cds-serve", "test": "npx jest --silent", + "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./test", + "add-telemetry": "npm add @cap-js/telemetry", + "add-attachments": "npm add @cap-js/attachments && cp xmpls/attachments.cds ./srv && cp -r xmpls/content ./db/data/content", + "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 && cp xmpls/audit-log.test.js ./test", + "add-remote-service": "cp -r xmpls/remote-service/ .", + "add-messaging": "cp -r xmpls/messaging/ .", + "add-all-xmpls": "npm run add-remote-service && 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" }, "private": true, @@ -61,7 +70,8 @@ "users": { "alice": { "roles": [ - "support" + "support", + "admin" ] }, "bob": { diff --git a/xmpls/remote-service/package.json b/xmpls/remote-service/package.json index c8fbde5..7a5b8cf 100644 --- a/xmpls/remote-service/package.json +++ b/xmpls/remote-service/package.json @@ -27,6 +27,15 @@ "watch": "cds watch", "start": "cds-serve", "test": "npx jest --silent", + "add-change-tracking": "npm add @cap-js/change-tracking && cp xmpls/change-tracking.cds ./srv && cp xmpls/change-tracking.test.js ./test", + "add-telemetry": "npm add @cap-js/telemetry", + "add-attachments": "npm add @cap-js/attachments && cp xmpls/attachments.cds ./srv && cp -r xmpls/content ./db/data/content", + "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 && cp xmpls/audit-log.test.js ./test", + "add-remote-service": "cp -r xmpls/remote-service/ .", + "add-messaging": "cp -r xmpls/messaging/ .", + "add-all-xmpls": "npm run add-remote-service && 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" }, "private": true, @@ -58,7 +67,8 @@ "users": { "alice": { "roles": [ - "support" + "support", + "admin" ] }, "bob": {