Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests & Unit tests for S/4HANA business process scenario #40

Merged
merged 5 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -26,6 +26,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm install sqlite3
- run: npm install @cap-js/sqlite
- run: npm run-script test:unit
- run: npm run-script test:integration
3 changes: 2 additions & 1 deletion db/csv/my.businessPartnerValidation-Addresses.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ID;addressId;country;cityName;streetName;postalCode;notifications_ID;businessPartnerId
58040e66-1dcd-4ffb-ab10-fdce32028b79;"124462";"DE";"Walldorf";"Dietmar-Hopp-Allee 162";"560066";2c728381-72ce-4fdd-8293-8add71579666;17100001
64e718c9-ff99-47f1-8ca3-950c850777d4;"124463";"DE";"Walldorf";"some street";"123456";ff0bc005-710c-4097-a687-64ef380498f4;17100002
64e718c9-ff99-47f1-8ca3-950c850777d4;"124463";"DE";"Walldorf";"some street";"123456";ff0bc005-710c-4097-a687-64ef380498f4;17100002
64e718c9-ff99-47f1-8ca3-950c850777e5;"124464";"DE";"Walldorf";"some street";"123456";16f00c9c-323f-4ce4-876f-efaefe1c6f69;17100003
3 changes: 2 additions & 1 deletion db/csv/my.businessPartnerValidation-Notifications.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ID;businessPartnerId;businessPartnerName;verificationStatus_code
2c728381-72ce-4fdd-8293-8add71579666;17100001;TestData1;N
ff0bc005-710c-4097-a687-64ef380498f4;17100002;TestData2;P
ff0bc005-710c-4097-a687-64ef380498f4;17100002;TestData2;P
16f00c9c-323f-4ce4-876f-efaefe1c6f69;17100003;TestData3;P
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
},
"scripts": {
"start": "npx cds-serve",
"test": "npm install @cap-js/sqlite && npm run test:integration",
"test:integration": "mocha tests/mocha.test.js --timeout 28000",
"test": "npm run test:integration",
"test:integration": "jest tests/integration/BPValidation.test.js",
"test:unit": "jest tests/unit/service.test.js",
"test:legacy": "mocha tests/chai-test.js --timeout 15000 --exit"
"test:legacy": "mocha tests/legacy/chai-test.js --timeout 15000 --exit"
},
"devDependencies": {
"@cap-js/sqlite": "^1.1.0",
Expand Down
50 changes: 38 additions & 12 deletions srv/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ const cds = require('@sap/cds');
req.data.isModified = true;
});

srv.after("PATCH", "Addresses", (data, req) => {
const isValidPinCode = postcodeValidator(data.postalCode, data.country);
if(!isValidPinCode){
return req.error({code: '400', message: "invalid postal code", numericSeverity:2, target: 'postalCode'});
}
return req.info({numericSeverity:1, target: 'postalCode'});
srv.after("PATCH", "Addresses", async (data, req) => {
srv.LOG.info("Received address in PATCH", data);
let isValidPinCode = true;
if(data && data.postalCode){
isValidPinCode = await this.validatePostcode(data, this.LOG);
}

if(!isValidPinCode) {
return req.error({ code: '400', message: "invalid postal code", numericSeverity: 2, target: 'postalCode' });
}
});

await super.init()
Expand All @@ -90,19 +94,41 @@ const cds = require('@sap/cds');
}
}

async validatePostcode(data, LOG){
const {Addresses} = this.entities;
const {postcodeValidator} = require('postcode-validator');
let isValidPinCode;
if(data.postalCode){
const address = await cds.run(SELECT.one(Addresses).where({ ID: data.ID }));
isValidPinCode = postcodeValidator(data.postalCode, address.country);
LOG.info("isValidPinCode ",isValidPinCode);
return isValidPinCode;
}
}

async emitEvent(bupaSrv, result, LOG){
const {BusinessPartner, BusinessPartnerAddress} = this.entities;
const resultJoin = await cds.run(SELECT.one("my.businessPartnerValidation.Notifications as N").leftJoin("my.businessPartnerValidation.Addresses as A").on("N.businessPartnerId = A.businessPartnerId").where({"N.ID": result.ID}));
const {BusinessPartner, BusinessPartnerAddress, Notifications} = this.entities;
const resultJoin = await cds.run(
SELECT.one(Notifications, notification => {
notification('*'),
notification.addresses((addresses) => {
addresses('*')
});
})
.where({"ID": result.ID})
)

const addressResult = resultJoin.addresses[0];
const statusValues={"N":"NEW", "P":"PROCESS", "INV":"INVALID", "V":"VERIFIED"}

if(resultJoin.isModified){
if(addressResult.isModified){
let payload = {
streetName: resultJoin.streetName,
postalCode: resultJoin.postalCode
streetName: addressResult.streetName,
postalCode: addressResult.postalCode
}

LOG.info("<<<<payload address", payload)
let res = await bupaSrv.run(UPDATE(BusinessPartnerAddress).set(payload).where({businessPartnerId:resultJoin.businessPartnerId, addressId:resultJoin.addressId}));
let res = await bupaSrv.run(UPDATE(BusinessPartnerAddress).set(payload).where({businessPartnerId:resultJoin.businessPartnerId, addressId:addressResult.addressId}));

LOG.info(`address update to S/4 Backend system`, res);
}
Expand Down
Loading
Loading