-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from cap-js/add-scripts-test
Add scripts for test pipeline
- Loading branch information
Showing
14 changed files
with
436 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "[email protected]" | ||
}); | ||
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); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: "[email protected]" | ||
}] | ||
}] | ||
} | ||
); | ||
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: "[email protected]" | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.