Skip to content

Commit

Permalink
Merge pull request ONDC-Official#17 from bluecypher/main
Browse files Browse the repository at this point in the history
validation fixes
  • Loading branch information
BLR-0118 authored Mar 28, 2023
2 parents 18ee787 + 7fab4fd commit 539d00c
Show file tree
Hide file tree
Showing 24 changed files with 112 additions and 117 deletions.
1 change: 0 additions & 1 deletion utilities/log-validation-utility/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ verification-logs
test_logs
dbfiles
test.js
public/
!README.md
!LICENSE.md
*.md
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,6 @@ const addFormats = require("ajv-formats");
addFormats(ajv);
require("ajv-errors")(ajv);

// transform_on_search_schema = (payload) => {
// transformed_payload = payload;
// bpp_providers = transformed_payload["message"]["catalog"]["bpp/providers"];
// bpp_providers.forEach((provider) => {
// if (provider.hasOwnProperty("@ondc/org/fssai_license_no")) {
// fssai = provider["@ondc/org/fssai_license_no"];
// items = provider["items"];
// items.forEach((item) => {
// item["@ondc/org/fssai_license_no"] = fssai;
// });
// }

// return transformed_payload;
// });
// };
const formatted_error = (errors) => {
error_list = [];
let status = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
$schema: "http://json-schema.org/draft-04/schema#",
type: "object",
properties: {
context: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ module.exports = {
type: "array",
items: {
type: "string",
pattern: "^(?!\\s*$).+\\.(jpeg|jpg|jfif|gif|png|ico)$",
},
},
},
Expand Down Expand Up @@ -86,8 +85,6 @@ module.exports = {
type: "array",
items: {
type: "string",
pattern:
"^(?!\\s*$).+\\.(jpeg|jpg|jfif|gif|png|ico)$",
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion utilities/log-validation-utility/utils/retail/retCancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const checkCancel = (dirPath, msgIdSet) => {
try {
res = checkContext(cancel.context, constants.RET_CANCEL);
if (!res.valid) {
cnclObj = res.ERRORS;
Object.assign(cnclObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down
6 changes: 3 additions & 3 deletions utilities/log-validation-utility/utils/retail/retConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const checkConfirm = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_CONFIRM} API`); //checking context
res = checkContext(confirm.context, constants.RET_CONFIRM);
if (!res.valid) {
cnfrmObj = res.ERRORS;
Object.assign(cnfrmObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -277,7 +277,7 @@ const checkConfirm = (dirPath, msgIdSet) => {

if (
!_.isEqual(
confirm.payment["@ondc/org/settlement_details"],
confirm.payment["@ondc/org/settlement_details"][0],
dao.getValue("sttlmntdtls")
)
) {
Expand Down Expand Up @@ -325,7 +325,7 @@ const checkConfirm = (dirPath, msgIdSet) => {
);
console.log("confirm quote", confirm.quote);
if (!_.isEqual(dao.getValue("quoteObj"), confirm.quote)) {
cnfrmObj.quoteObj = `Quote Objects in /${constants.RET_ONSELECT} and /${constants.RET_CONFIRM} do not match`;
cnfrmObj.quoteObj = `Discrepancies between the quote object in /${constants.RET_ONSELECT} and /${constants.RET_CONFIRM}`;
}
} catch (error) {
console.log(
Expand Down
7 changes: 4 additions & 3 deletions utilities/log-validation-utility/utils/retail/retInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const checkInit = (dirPath, msgIdSet) => {
try {
console.log(`Validating Schema for ${constants.RET_INIT} API`);
const vs = validateSchema("retail", constants.RET_INIT, init);
console.log("DEBUGGG", vs);
if (vs != "error") {
// console.log(vs);
Object.assign(initObj, vs);
}
} catch (error) {
Expand All @@ -29,7 +29,7 @@ const checkInit = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_INIT} API`); //checking context
res = checkContext(init.context, constants.RET_INIT);
if (!res.valid) {
initObj = res.ERRORS;
Object.assign(initObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -255,7 +255,8 @@ const checkInit = (dirPath, msgIdSet) => {
console.log(`!!File not found for /${constants.RET_INIT} API!`);
} else {
console.log(
`!!Some error occurred while checking /${constants.RET_INIT} API`
`!!Some error occurred while checking /${constants.RET_INIT} API`,
err
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const checkOnCancel = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_ONCANCEL} API`); //checking context
res = checkContext(on_cancel.context, constants.RET_ONCANCEL);
if (!res.valid) {
onCnclObj = res.ERRORS;
Object.assign(onCnclObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down
11 changes: 6 additions & 5 deletions utilities/log-validation-utility/utils/retail/retOnConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const checkOnConfirm = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_ONCONFIRM} API`); //checking context
res = checkContext(on_confirm.context, constants.RET_ONCONFIRM);
if (!res.valid) {
onCnfrmObj = res.ERRORS;
Object.assign(onCnfrmObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -142,9 +142,10 @@ const checkOnConfirm = (dirPath, msgIdSet) => {
if (
cnfrmOrdrUpdtd &&
(!on_confirm.updated_at ||
_.gte(cnfrmOrdrUpdtd, on_confirm.updated_at))
_.gte(cnfrmOrdrUpdtd, on_confirm.updated_at) ||
on_confirm.updated_at != dao.getValue("tmpstmp"))
) {
onCnfrmObj.updtdtmstmp = `order.updated_at timestamp should be updated (Default fulfillment state is added)`;
onCnfrmObj.updtdtmstmp = `order.updated_at timestamp should be updated as per the context.timestamp (since default fulfillment state is added)`;
}
}

Expand Down Expand Up @@ -347,7 +348,7 @@ const checkOnConfirm = (dirPath, msgIdSet) => {
`Comparing Quote object for /${constants.RET_ONSELECT} and /${constants.RET_ONCONFIRM}`
);
if (!_.isEqual(dao.getValue("quoteObj"), on_confirm.quote)) {
onCnfrmObj.onQuoteObj = `Quote Object in /${constants.RET_ONSELECT} and /${constants.RET_ONCONFIRM} do not match`;
onCnfrmObj.onQuoteObj = `Discrepancies between the quote object /${constants.RET_ONSELECT} and /${constants.RET_ONCONFIRM}`;
}
} catch (error) {
// onCnfrmObj.onQuoteObj = `Quote Object in /on_init and /${constants.RET_ONCONFIRM} mismatch`;
Expand Down Expand Up @@ -381,7 +382,7 @@ const checkOnConfirm = (dirPath, msgIdSet) => {
);

if (!_.isEqual(dao.getValue("cnfrmpymnt"), on_confirm.payment)) {
`payment object mismatches in /${constants.RET_CONFIRM} & /${constants.RET_ONCONFIRM}`;
onCnfrmObj.pymntObj = `payment object mismatches in /${constants.RET_CONFIRM} & /${constants.RET_ONCONFIRM}`;
}
} catch (error) {
console.log(
Expand Down
13 changes: 7 additions & 6 deletions utilities/log-validation-utility/utils/retail/retOnInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const checkOnInit = (dirPath, msgIdSet) => {
var on_init = fs.readFileSync(dirPath + `/${constants.RET_ONINIT}.json`);

on_init = JSON.parse(on_init);
console.log(`Validating Schema for /${constants.RET_ONINIT} API`);

try {
console.log(`Validating Schema for /${constants.RET_ONINIT} API`);
const vs = validateSchema("retail", constants.RET_ONINIT, on_init);
if (vs != "error") {
// console.log(vs);
Expand All @@ -31,7 +31,7 @@ const checkOnInit = (dirPath, msgIdSet) => {
try {
res = checkContext(on_init.context, constants.RET_ONINIT);
if (!res.valid) {
onInitObj = res.ERRORS;
Object.assign(onInitObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -313,7 +313,7 @@ const checkOnInit = (dirPath, msgIdSet) => {
`Checking Quote Object in /${constants.RET_ONSELECT} and /${constants.RET_ONINIT}`
);
if (!_.isEqual(dao.getValue("quoteObj"), on_init.quote)) {
onInitObj.quoteErr = `Quote object mismatches in /${constants.RET_ONSELECT} and /${constants.RET_ONINIT}`;
onInitObj.quoteErr = `Discrepancies between the quote object in /${constants.RET_ONSELECT} and /${constants.RET_ONINIT}`;
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -361,7 +361,7 @@ const checkOnInit = (dirPath, msgIdSet) => {
onInitObj.sttlmntcntrparty = `settlement_counterparty is expected to be 'seller-app' in @ondc/org/settlement_details`;
}
} catch (error) {
console.err(
console.log(
`!!Error while checking payment object in /${constants.RET_ONINIT}`
);
}
Expand All @@ -373,7 +373,7 @@ const checkOnInit = (dirPath, msgIdSet) => {
if (on_init.payment.hasOwnProperty("@ondc/org/settlement_details"))
dao.setValue(
"sttlmntdtls",
on_init.payment["@ondc/org/settlement_details"]
on_init.payment["@ondc/org/settlement_details"][0]
);
else {
onInitObj.pymntSttlmntObj = `payment settlement_details missing in /${constants.RET_ONINIT}`;
Expand All @@ -390,7 +390,8 @@ const checkOnInit = (dirPath, msgIdSet) => {
console.log(`!!File not found for /${constants.RET_ONINIT} API!`);
} else {
console.log(
`!!Some error occurred while checking /${constants.RET_ONINIT} API`
`!!Some error occurred while checking /${constants.RET_ONINIT} API`,
err
);
}
}
Expand Down
33 changes: 18 additions & 15 deletions utilities/log-validation-utility/utils/retail/retOnSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ const checkOnSelect = (dirPath, msgIdSet) => {
on_select = fs.readFileSync(dirPath + `/${constants.RET_ONSELECT}.json`);

on_select = JSON.parse(on_select);

try {
console.log(`Validating Schema for /${constants.RET_ONSELECT} API`);
const vs = validateSchema("retail", constants.RET_ONSELECT, on_select);
if (vs != "error") {
// console.log(vs);
Object.assign(onSlctObj, vs);
console.log(`Checking context for /${constants.RET_ONSELECT} API`); //checking context
res = checkContext(on_select.context, constants.RET_ONSELECT);
if (!res.valid) {
Object.assign(onSlctObj, res.ERRORS);
}
} catch (error) {
console.log(
`!!Error occurred while performing schema validation for /${constants.RET_ONSELECT}`,
`!!Some error occurred while checking /${constants.RET_ONSELECT} context`,
error
);
}

try {
console.log(`Checking context for /${constants.RET_ONSELECT} API`); //checking context
res = checkContext(on_select.context, constants.RET_ONSELECT);
if (!res.valid) {
onSlctObj = res.ERRORS;
console.log(`Validating Schema for /${constants.RET_ONSELECT} API`);
const vs = validateSchema("retail", constants.RET_ONSELECT, on_select);
if (vs != "error") {
// console.log(vs);
Object.assign(onSlctObj, vs);
}
} catch (error) {
console.log(
`!!Some error occurred while checking /${constants.RET_ONSELECT} context`,
`!!Error occurred while performing schema validation for /${constants.RET_ONSELECT}`,
error
);
}
Expand Down Expand Up @@ -294,11 +294,14 @@ const checkOnSelect = (dirPath, msgIdSet) => {
if (element.item.hasOwnProperty("quantity")) {
if (
_.gt(
element.item.quantity.available.count,
element.item.quantity.maximum.count
parseFloat(element.item.quantity.available.count),
parseFloat(element.item.quantity.maximum.count)
)
) {
onSlctObj.qntCnt = `available count can't be greater than maximum count for item id: ${element["@ondc/org/item_id"]}`;
let key = `qntcnt${i}`;
onSlctObj[
key
] = `available count can't be greater than maximum count for item id: ${element["@ondc/org/item_id"]}`;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const checkOnStatus = (dirPath, msgIdSet) => {
console.log("Checking context for /${constants.RET_ONSTATUS} API"); //checking context
res = checkContext(on_status.context, "on_status");
if (!res.valid) {
onStatObj = res.ERRORS;
Object.assign(onStatObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const checkOnSupport = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_ONSUPPORT} API`); //checking context
res = checkContext(on_support.context, constants.RET_ONSUPPORT);
if (!res.valid) {
onSprtObj = res.ERRORS;
Object.assign(onSprtObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const checkOnTrack = (dirPath, msgIdSet) => {
try {
res = checkContext(on_track.context, "on_track");
if (!res.valid) {
onTrckObj = res.ERRORS;
Object.assign(onTrckObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down
4 changes: 2 additions & 2 deletions utilities/log-validation-utility/utils/retail/retOnUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const checkOnUpdate = (dirPath, msgIdSet) => {
console.log(`Checking context for /${constants.RET_ONUPDATE} API`); //checking context
res = checkContext(on_update.context, constants.RET_ONUPDATE);
if (!res.valid) {
onUpdtObj = res.ERRORS;
Object.assign(onUpdtObj, res.ERRORS);
}
} catch (error) {
console.log(
Expand Down Expand Up @@ -205,7 +205,7 @@ const checkOnUpdate = (dirPath, msgIdSet) => {
`Comparing individual item's total price and unit price `
);
if (!element.hasOwnProperty("item")) {
onSlctObj.priceBreakup = `Item's unit price missing in quote.breakup for item id ${element["@ondc/org/item_id"]}`;
onUpdtObj.priceBreakup = `Item's unit price missing in quote.breakup for item id ${element["@ondc/org/item_id"]}`;
} else if (
parseFloat(element.item.price.value) *
element["@ondc/org/item_quantity"].count !=
Expand Down
Loading

0 comments on commit 539d00c

Please sign in to comment.