From 3f3a0ef0e1a70d964d74da9b236a3b058db0cc1d Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Thu, 4 Jan 2024 12:34:23 +0530 Subject: [PATCH 1/8] fixed bugs and exceptions --- .../schema/B2B_json_schema/keywords/init.js | 2 +- .../schema/B2B_json_schema/keywords/onInit.js | 2 +- .../schema/B2B_json_schema/keywords/search.js | 4 +- .../schema/B2B_json_schema/v2/confirm.js | 2 +- .../schema/B2B_json_schema/v2/init.js | 2 +- .../schema/B2B_json_schema/v2/on_confirm.js | 2 - .../schema/B2B_json_schema/v2/on_init.js | 2 - .../schema/B2B_json_schema/v2/on_search.js | 2 +- .../schema/B2B_json_schema/v2/search.js | 3 ++ .../schema/B2B_json_schema/v2/select.js | 2 +- .../v1.2/confirmSchema.js | 19 ++++++++- .../v1.2/keywords/init.js | 2 +- .../v1.2/keywords/onInit.js | 2 +- .../v1.2/keywords/search.js | 4 +- .../v1.2/onCancelSchema.js | 15 +++++++ .../v1.2/onConfirmSchema.js | 17 +++++++- .../v1.2/onStatusSchema.js | 39 +++++++++++++++++++ .../v1.2/onUpdateSchema.js | 15 +++++++ .../utils/ContextVal.js | 3 +- .../utils/logistics/logInit.js | 6 +-- 20 files changed, 119 insertions(+), 26 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/init.js index 18a4db3..8f448e9 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/init.js @@ -1,6 +1,6 @@ module.exports = { isLengthValid: (data) => { - if (data.name.length + data.building.length + data.locality.length > 190) + if (data?.name?.length + data?.building?.length + data?.locality?.length > 190) return false; else return true; }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/onInit.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/onInit.js index b31f2e2..f4081b8 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/onInit.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/onInit.js @@ -1,7 +1,7 @@ module.exports = { isQuoteMatching: (data) => { let quotePrice = parseFloat(data?.price?.value); - const breakupArr = data.breakup; + const breakupArr = data?.breakup; let totalBreakup = 0; breakupArr.forEach((breakup) => { totalBreakup += parseFloat(breakup?.price?.value); diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/search.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/search.js index 6588a9e..7a14c5b 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/search.js @@ -1,7 +1,7 @@ module.exports = { isEndTimeGreater: (data) => { - const startTime = parseInt(data.start); - const endTime = parseInt(data.end); + const startTime = parseInt(data?.start); + const endTime = parseInt(data?.end); return startTime < endTime; }, }; diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js index 5adfe0d..082d0fc 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js @@ -308,7 +308,7 @@ module.exports = { gps: { type: "string", pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", + errorMessage: "Incorrect gps value (minimum of six decimal places are required)", }, address: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js index 9b9db05..336f703 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js @@ -287,7 +287,7 @@ module.exports = { type: "string", pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", + errorMessage: "Incorrect gps value (minimum of six decimal places are required)", }, address: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js index 3e87a93..d6f47d8 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js @@ -343,8 +343,6 @@ module.exports = { }, gps: { type: "string", - pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", }, address: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js index d47c1fe..35dfa68 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js @@ -300,8 +300,6 @@ module.exports = { properties: { gps: { type: "string", - pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", }, address: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js index 13d05ca..d8d3584 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js @@ -238,7 +238,7 @@ module.exports = { type: "string", pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", + errorMessage: "Incorrect gps value (minimum of six decimal places are required)", }, address: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js index a10ad82..79d7f96 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js @@ -123,6 +123,9 @@ module.exports = { properties: { gps: { type: "string", + pattern: + "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", + errorMessage: "Incorrect gps value (minimum of six decimal places are required)", }, area_code: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index 444749f..218b65f 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -235,7 +235,7 @@ module.exports = { type: "string", pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value", + errorMessage: "Incorrect gps value (minimum of six decimal places are required)", }, area_code: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/confirmSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/confirmSchema.js index c2ac4e6..1b3b5d0 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/confirmSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/confirmSchema.js @@ -172,6 +172,21 @@ module.exports = { }, required: ["code"], }, + time: { + type: "object", + properties: { + label: { + type: "string", + }, + duration: { + type: "string", + }, + timestamp: { + type: "string", + }, + }, + required: ["label", "duration", "timestamp"], + }, }, required: ["id", "category_id", "descriptor", "fulfillment_id"], // anyOf: [ @@ -1038,7 +1053,6 @@ module.exports = { code: { type: "string", enum: constants.TERMS, - }, list: { type: "array", @@ -1060,7 +1074,8 @@ module.exports = { required: ["code", "list"], }, minItems: 2, - errorMessage: "both 'bpp_terms' and 'bap_terms' tags are required (logistics buyer NP must accept LSP terms. If not accepted, LSP can NACK /confirm with error code 65002)", + errorMessage: + "both 'bpp_terms' and 'bap_terms' tags are required (logistics buyer NP must accept LSP terms. If not accepted, LSP can NACK /confirm with error code 65002)", }, }, additionalProperties: false, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/init.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/init.js index 18a4db3..8f448e9 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/init.js @@ -1,6 +1,6 @@ module.exports = { isLengthValid: (data) => { - if (data.name.length + data.building.length + data.locality.length > 190) + if (data?.name?.length + data?.building?.length + data?.locality?.length > 190) return false; else return true; }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/onInit.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/onInit.js index af5d333..a0aebf6 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/onInit.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/onInit.js @@ -1,7 +1,7 @@ module.exports = { isQuoteMatching: (data) => { let quotePrice = parseFloat(data?.price?.value); - const breakupArr = data.breakup; + const breakupArr = data?.breakup; let totalBreakup = 0; breakupArr.forEach((breakup) => { totalBreakup += parseFloat(breakup?.price?.value); diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/search.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/search.js index 6588a9e..7a14c5b 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/keywords/search.js @@ -1,7 +1,7 @@ module.exports = { isEndTimeGreater: (data) => { - const startTime = parseInt(data.start); - const endTime = parseInt(data.end); + const startTime = parseInt(data?.start); + const endTime = parseInt(data?.end); return startTime < endTime; }, }; diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onCancelSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onCancelSchema.js index 79705df..56701b7 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onCancelSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onCancelSchema.js @@ -159,6 +159,21 @@ module.exports = { }, required: ["code"], }, + time: { + type: "object", + properties: { + label: { + type: "string", + }, + duration: { + type: "string", + }, + timestamp: { + type: "string", + }, + }, + required: ["label", "duration", "timestamp"], + }, }, required: ["id", "category_id", "descriptor", "fulfillment_id"], }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js index ad3d244..ff7b510 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js @@ -198,8 +198,23 @@ module.exports = { }, required: ["code"], }, + time: { + type: "object", + properties: { + label: { + type: "string", + }, + duration: { + type: "string", + }, + timestamp: { + type: "string", + }, + }, + required: ["label", "duration", "timestamp"], + }, }, - required: ["id", "category_id", "descriptor"], + required: ["id", "category_id", "descriptor","time","fulfillment_id"], }, }, quote: { diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js index 0b7fbf5..1017c08 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js @@ -163,6 +163,21 @@ module.exports = { }, required: ["code"], }, + time: { + type: "object", + properties: { + label: { + type: "string", + }, + duration: { + type: "string", + }, + timestamp: { + type: "string", + }, + }, + required: ["label", "duration", "timestamp"], + }, }, required: ["id", "category_id", "descriptor", "fulfillment_id"], }, @@ -625,6 +640,30 @@ module.exports = { }, }, }, + + if: { properties: { type: { const: "ON-ORDER" } } }, + then: { + properties: { + collected_by: { + const: "BAP", + }, + status:{ + const:"PAID" + } + }, + }, + + if: { properties: { type: { const: "POST-FULFILLMENT" } } }, + then: { + properties: { + collected_by: { + const: "BAP", + }, + status:{ + const:"NOT-PAID" + } + }, + }, required: ["type", "collected_by","status"], }, billing: { diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onUpdateSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onUpdateSchema.js index ab0a17a..7aff9a5 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onUpdateSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onUpdateSchema.js @@ -149,6 +149,21 @@ module.exports = { }, }, }, + time: { + type: "object", + properties: { + label: { + type: "string", + }, + duration: { + type: "string", + }, + timestamp: { + type: "string", + }, + }, + required: ["label", "duration", "timestamp"], + }, }, required: ["id", "fulfillment_id", "category_id", "descriptor"], }, diff --git a/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js b/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js index 11175d7..8749ce0 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js @@ -15,7 +15,7 @@ const checkContextVal = (payload, msgIdSet, i) => { let data = payload.context; let domain = payload.context.domain; let maxTimeDiff = 5000; - if (domain === "ONDC:RET10" && payload?.context?.version === "2.0.1") { + if (payload?.context?.version === "2.0.1") { if (action === "init") { maxTimeDiff = utils.iso8601DurationToSeconds(payload.context.ttl); dao.setValue("maxTimeDiff", maxTimeDiff); @@ -25,7 +25,6 @@ const checkContextVal = (payload, msgIdSet, i) => { } else if (domain === "nic2004:60232") { maxTimeDiff = 1000; } else if ( - domain === "ONDC:RET10" && payload?.context?.version === "2.0.2" ) { if (action === "select") { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js index 93cdc26..ef36eae 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js @@ -6,11 +6,7 @@ const utils = require("../utils"); const checkInit = (data, msgIdSet) => { const billing = data.message.order.billing const billingAdd= billing.address - const len = billingAdd.name.length + billingAdd.building.length +billingAdd.locality.length - console.log(billingAdd.name.length,billingAdd.building.length,billingAdd.locality.length); - console.log("length",len); - if (billingAdd.name.length + billingAdd.building.length +billingAdd.locality.length > 190) return true - else false + const initObj = {}; let init = data; let p2h2p = false; From afb4235233153b8deceef44b7b0115745b9a8244 Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Mon, 15 Jan 2024 13:22:55 +0530 Subject: [PATCH 2/8] updated b2b schema --- .../schema/B2B_json_schema/v2/confirm.js | 111 +++++++++++++----- .../schema/B2B_json_schema/v2/init.js | 27 ++++- .../schema/B2B_json_schema/v2/on_confirm.js | 11 +- .../schema/B2B_json_schema/v2/on_init.js | 110 +++++++++++++---- .../schema/B2B_json_schema/v2/on_search.js | 32 ++++- .../schema/B2B_json_schema/v2/on_select.js | 25 +++- .../schema/B2B_json_schema/v2/on_status.js | 3 + .../schema/B2B_json_schema/v2/search.js | 2 +- .../schema/B2B_json_schema/v2/select.js | 86 +++----------- .../v1.2/onConfirmSchema.js | 2 +- .../v1.2/onStatusSchema.js | 2 +- .../utils/b2b/b2bOnSearch.js | 14 ++- .../utils/b2b/b2bSearch.js | 59 +++++----- .../utils/logistics/logOnInit.js | 17 +-- 14 files changed, 328 insertions(+), 173 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js index 082d0fc..409f3ef 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js @@ -58,7 +58,7 @@ module.exports = { type: "string", const: { $data: "/select/0/context/transaction_id" }, errorMessage: - "Transaction ID should be same across the transaction: ${/search/0/context/transaction_id}", + "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", }, message_id: { type: "string", @@ -70,7 +70,7 @@ module.exports = { errorMessage: "Message ID should not be equal to transaction_id: ${1/transaction_id}", }, - ] + ], }, timestamp: { type: "string", @@ -119,13 +119,12 @@ module.exports = { locations: { type: "array", const: { $data: "/init/0/message/order/provider/locations" }, - errorMessage:"mismatch from /init", + errorMessage: "mismatch from /init", items: { type: "object", properties: { id: { type: "string", - }, }, required: ["id"], @@ -209,12 +208,22 @@ module.exports = { type: "string", anyOf: [ { - const: { $data: "/init/0/message/order/items/0/tags/0/list/0/value" }, + const: { + $data: + "/select/0/message/order/items/0/tags/0/list/0/value", + }, + errorMessage: + "Buyer terms should be same as provided in /select", }, { - const: { $data: "/init/0/message/order/items/0/tags/0/list/1/value" }, - } - ] + const: { + $data: + "/select/0/message/order/items/0/tags/0/list/1/value", + }, + errorMessage: + "Buyer terms should be same as provided in /select", + }, + ], }, }, required: ["descriptor", "value"], @@ -276,7 +285,7 @@ module.exports = { const: { $data: "/init/0/message/order/billing/phone" }, }, }, - + required: ["name", "address", "state", "city", "tax_id", "phone"], }, fulfillments: { @@ -307,8 +316,10 @@ module.exports = { properties: { gps: { type: "string", - pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value (minimum of six decimal places are required)", + pattern: + "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", + errorMessage: + "Incorrect gps value (minimum of six decimal places are required)", }, address: { type: "string", @@ -421,12 +432,18 @@ module.exports = { type: "string", anyOf: [ { - const: { $data: "/init/0/message/order/fulfillments/0/tags/0/list/0/value" }, + const: { + $data: + "/init/0/message/order/fulfillments/0/tags/0/list/0/value", + }, }, { - const: { $data: "/init/0/message/order/fulfillments/0/tags/0/list/1/value" }, - } - ] + const: { + $data: + "/init/0/message/order/fulfillments/0/tags/0/list/1/value", + }, + }, + ], }, }, if: { @@ -501,7 +518,14 @@ module.exports = { }, "@ondc/org/title_type": { type: "string", - enum: ["item", "discount", "packing", "delivery", "tax", "misc"] + enum: [ + "item", + "discount", + "packing", + "delivery", + "tax", + "misc", + ], }, price: { type: "object", @@ -602,6 +626,7 @@ module.exports = { type: "string", enum: ["PAID", "NOT-PAID"], }, + type: { type: "string", enum: [ @@ -612,6 +637,7 @@ module.exports = { }, collected_by: { type: "string", + enum: ["BAP", "BPP"], }, "@ondc/org/buyer_app_finder_fee_type": { type: "string", @@ -619,6 +645,16 @@ module.exports = { "@ondc/org/buyer_app_finder_fee_amount": { type: "string", }, + "@ondc/org/settlement_basis": { + type: "string", + }, + "@ondc/org/settlement_window": { + type: "string", + }, + "@ondc/org/withholding_amount": { + type: "string", + }, + "@ondc/org/settlement_details": { type: "array", items: { @@ -687,14 +723,34 @@ module.exports = { }, }, }, - required: [ - "params", - "status", - "type", - "collected_by", - "@ondc/org/buyer_app_finder_fee_type", - "@ondc/org/buyer_app_finder_fee_amount", - ], + if: { properties: { collected_by: { const: "BPP" } } }, + then: { + required: [ + "params", + "status", + "type", + "collected_by", + "@ondc/org/buyer_app_finder_fee_type", + "@ondc/org/buyer_app_finder_fee_amount", + "@ondc/org/settlement_basis", + "@ondc/org/settlement_window", + "@ondc/org/withholding_amount", + "@ondc/org/settlement_details", + ], + }, + else: { + required: [ + "params", + "status", + "type", + "collected_by", + "@ondc/org/buyer_app_finder_fee_type", + "@ondc/org/buyer_app_finder_fee_amount", + "@ondc/org/settlement_basis", + "@ondc/org/settlement_window", + "@ondc/org/withholding_amount", + ], + }, }, }, tags: { @@ -738,16 +794,16 @@ module.exports = { type: "string", const: { $data: "3/context/timestamp" }, errorMessage: - "created_at does not match context timestamp - ${3/context/timestamp}", + "does not match context timestamp - ${3/context/timestamp}", }, updated_at: { type: "string", const: { $data: "3/context/timestamp" }, errorMessage: - "updated_at does not match context timestamp - ${3/context/timestamp}", + "does not match context timestamp - ${3/context/timestamp}", }, }, - additionalProperties:false, + additionalProperties: false, required: [ "id", "state", @@ -765,5 +821,6 @@ module.exports = { required: ["order"], }, }, + isFutureDated: true, required: ["context", "message"], }; diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js index 336f703..47ab2d3 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js @@ -58,7 +58,7 @@ module.exports = { type: "string", const: { $data: "/select/0/context/transaction_id" }, errorMessage: - "Transaction ID should be same across the transaction: ${/search/0/context/transaction_id}", + "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", }, message_id: { type: "string", @@ -127,6 +127,7 @@ module.exports = { } }, required: ["id", "locations"], + additionalProperties:false }, items: { type: "array", @@ -201,6 +202,22 @@ module.exports = { }, value: { type: "string", + anyOf: [ + { + const: { + $data: + "/select/0/message/order/items/0/tags/0/list/0/value", + }, + errorMessage:"Buyer terms should be same as provided in /select" + }, + { + const: { + $data: + "/select/0/message/order/items/0/tags/0/list/1/value", + }, + errorMessage:"Buyer terms should be same as provided in /select" + }, + ], }, }, required: ["descriptor", "value"], @@ -211,7 +228,7 @@ module.exports = { }, }, }, - required: ["id", "quantity"], + required: ["id", "fulfillment_ids","quantity","tags",], }, }, billing: { @@ -471,8 +488,12 @@ module.exports = { "POST-FULFILLMENT", ], }, + collected_by:{ + type:"string", + enum:["BAP","BPP"] + } }, - required: ["type"], + required: ["type","collected_by"], }, }, tags: { diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js index d6f47d8..9851d51 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js @@ -215,13 +215,15 @@ module.exports = { type: "string", anyOf: [ { - const: { $data: "/init/0/message/order/items/0/tags/0/list/0/value" }, + const: { $data: "/select/0/message/order/items/0/tags/0/list/0/value" }, + errorMessage:"Buyer terms should be same as provided in /select" }, { - const: { $data: "/init/0/message/order/items/0/tags/0/list/1/value" }, + const: { $data: "/select/0/message/order/items/0/tags/0/list/1/value" }, + errorMessage:"Buyer terms should be same as provided in /select" } ] - }, + } }, required: ["descriptor", "value"], }, @@ -803,9 +805,6 @@ module.exports = { updated_at: { type: "string", format: "date-time", - const: { $data: "3/context/timestamp" }, - errorMessage: - " should be updated as per context/timestamp - ${3/context/timestamp}", }, }, additionalProperties: false, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js index 35dfa68..6c72c5a 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js @@ -58,7 +58,7 @@ module.exports = { type: "string", const: { $data: "/select/0/context/transaction_id" }, errorMessage: - "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", + "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", }, message_id: { type: "string", @@ -75,7 +75,7 @@ module.exports = { errorMessage: "Message ID should not be equal to transaction_id: ${1/transaction_id}", }, - ] + ], }, timestamp: { type: "string", @@ -83,7 +83,7 @@ module.exports = { }, ttl: { type: "string", - format: "duration" + format: "duration", }, }, required: [ @@ -122,7 +122,9 @@ module.exports = { properties: { id: { type: "string", - const: { $data: "/init/0/message/order/provider/locations/0/id"} + const: { + $data: "/init/0/message/order/provider/locations/0/id", + }, }, }, required: ["id"], @@ -178,7 +180,7 @@ module.exports = { properties: { code: { type: "string", - enum:["BUYER_TERMS"] + enum: ["BUYER_TERMS"], }, }, required: ["code"], @@ -193,7 +195,7 @@ module.exports = { properties: { code: { type: "string", - enum:["ITEM_REQ","PACKAGING_REQ"] + enum: ["ITEM_REQ", "PACKAGING_REQ"], }, }, required: ["code"], @@ -202,12 +204,18 @@ module.exports = { type: "string", anyOf: [ { - const: { $data: "/init/0/message/order/items/0/tags/0/list/0/value" }, + const: { + $data: + "/init/0/message/order/items/0/tags/0/list/0/value", + }, }, { - const: { $data: "/init/0/message/order/items/0/tags/0/list/1/value" }, - } - ] + const: { + $data: + "/init/0/message/order/items/0/tags/0/list/1/value", + }, + }, + ], }, }, required: ["descriptor", "value"], @@ -269,7 +277,7 @@ module.exports = { const: { $data: "/init/0/message/order/billing/phone" }, }, }, - + required: ["name", "address", "state", "city", "tax_id", "phone"], }, fulfillments: { @@ -394,12 +402,18 @@ module.exports = { type: "string", anyOf: [ { - const: { $data: "/init/0/message/order/fulfillments/0/tags/0/list/0/value" }, + const: { + $data: + "/init/0/message/order/fulfillments/0/tags/0/list/0/value", + }, }, { - const: { $data: "/init/0/message/order/fulfillments/0/tags/0/list/1/value" }, - } - ] + const: { + $data: + "/init/0/message/order/fulfillments/0/tags/0/list/1/value", + }, + }, + ], }, }, if: { @@ -471,7 +485,14 @@ module.exports = { }, "@ondc/org/title_type": { type: "string", - enum: ["item", "discount", "packing", "delivery", "tax", "misc"] + enum: [ + "item", + "discount", + "packing", + "delivery", + "tax", + "misc", + ], }, price: { type: "object", @@ -547,7 +568,7 @@ module.exports = { }, }, isQuoteMatching: true, - + required: ["price", "breakup", "ttl"], }, payments: { @@ -555,12 +576,33 @@ module.exports = { items: { type: "object", properties: { + type: { + type: "string", + enum: [ + "PRE-FULFILLMENT", + "ON-FULFILLMENT", + "POST-FULFILLMENT", + ], + }, + collected_by: { + type: "string", + enum: ["BAP", "BPP"], + }, "@ondc/org/buyer_app_finder_fee_type": { type: "string", }, "@ondc/org/buyer_app_finder_fee_amount": { type: "string", }, + "@ondc/org/settlement_basis": { + type: "string", + }, + "@ondc/org/settlement_window": { + type: "string", + }, + "@ondc/org/withholding_amount": { + type: "string", + }, "@ondc/org/settlement_details": { type: "array", items: { @@ -629,10 +671,34 @@ module.exports = { }, }, }, - required: [ - "@ondc/org/buyer_app_finder_fee_type", - "@ondc/org/buyer_app_finder_fee_amount", - ], + if: { properties: { collected_by: { const: "BAP" } } }, + then: { + required: [ + "params", + "status", + "type", + "collected_by", + "@ondc/org/buyer_app_finder_fee_type", + "@ondc/org/buyer_app_finder_fee_amount", + "@ondc/org/settlement_basis", + "@ondc/org/settlement_window", + "@ondc/org/withholding_amount", + "@ondc/org/settlement_details", + ], + }, + else: { + required: [ + "params", + "status", + "type", + "collected_by", + "@ondc/org/buyer_app_finder_fee_type", + "@ondc/org/buyer_app_finder_fee_amount", + "@ondc/org/settlement_basis", + "@ondc/org/settlement_window", + "@ondc/org/withholding_amount", + ], + }, }, }, tags: { @@ -673,7 +739,7 @@ module.exports = { }, }, }, - additionalProperties:false, + additionalProperties: false, required: [ "provider", "provider_location", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js index d8d3584..4fbe8f6 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_search.js @@ -556,8 +556,38 @@ module.exports = { }, required: ["measure", "count"], }, + minimum: { + type: "object", + properties: { + measure: { + type: "object", + properties: { + unit: { + type: "string", + enum: [ + "unit", + "dozen", + "gram", + "kilogram", + "tonne", + "litre", + "millilitre", + ], + }, + value: { + type: "string", + }, + }, + required: ["unit", "value"], + }, + count: { + type: "string", + }, + }, + required: ["measure", "count"], + }, }, - required: ["unitized", "available", "maximum"], + required: ["unitized", "available"], }, category_ids: { type: "array", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js index 8e8591b..d10a53e 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js @@ -220,7 +220,7 @@ module.exports = { }, "@ondc/org/title_type": { type: "string", - enum: ["item", "discount", "packing", "delivery ", "tax", "misc"] + enum: ["item", "discount", "packing", "delivery", "tax", "misc"] }, price: { type: "object", @@ -324,8 +324,29 @@ module.exports = { required: ["price", "breakup", "ttl"], }, + payments: { + type: "array", + items: { + type: "object", + properties: { + type: { + type: "string", + enum: [ + "PRE-FULFILLMENT", + "ON-FULFILLMENT", + "POST-FULFILLMENT", + ], + }, + collected_by:{ + type:"string", + enum:["BAP","BPP"] + } + }, + required: ["type","collected_by"], + }, + }, }, - required: ["provider", "items", "quote"], + required: ["provider", "items", "quote","payments","fulfillments"], }, }, required: ["order"], diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js index ecaf332..be80d41 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js @@ -235,12 +235,15 @@ module.exports = { type: "string", enum: [ "Pending", + "Packed", + "Agent-assigned", "Out-for-pickup", "Order-picked-up", "In-transit", "At-destination-hub", "Out-for-delivery", "Order-delivered", + "Cancelled" ], }, }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js index 79d7f96..160bdd1 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/search.js @@ -255,7 +255,7 @@ module.exports = { }, }, additionalProperties:false, - required: ["item", "fulfillment", "payment", "tags"], + required: ["fulfillment", "payment", "tags"], }, }, required: ["intent"], diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index 218b65f..4cc3b84 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -56,9 +56,6 @@ module.exports = { }, transaction_id: { type: "string", - const: { $data: "/search/0/context/transaction_id" }, - errorMessage: - "Transaction ID should be same across the transaction: ${/search/0/context/transaction_id}", }, message_id: { type: "string", @@ -127,7 +124,7 @@ module.exports = { format: "duration", }, }, - required: ["id", "locations"], + required: ["id", "locations","ttl"], }, items: { type: "array", @@ -143,6 +140,12 @@ module.exports = { type: "string", }, }, + fulfillment_ids: { + type: "array", + items: { + type: "string", + }, + }, quantity: { type: "object", properties: { @@ -212,7 +215,7 @@ module.exports = { }, }, }, - required: ["id", "location_ids", "quantity"], + required: ["id", "location_ids", "quantity","tags","fulfillment_ids"], }, }, fulfillments: { @@ -220,6 +223,12 @@ module.exports = { items: { type: "object", properties: { + id: { + type: "string", + }, + type: { + type: "string", + }, stops: { type: "array", items: { @@ -291,73 +300,8 @@ module.exports = { }, required: ["person"], }, - tags: { - type: "array", - items: { - type: "object", - properties: { - descriptor: { - type: "object", - properties: { - code: { - type: "string", - enum: ["DELIVERY_TERMS"], - }, - }, - required: ["code"], - }, - list: { - type: "array", - items: { - type: "object", - properties: { - descriptor: { - type: "object", - properties: { - code: { - type: "string", - enum: [ - "INCOTERMS", - "NAMED_PLACE_OF_DELIVERY", - ], - }, - }, - required: ["code"], - }, - value: { - type: "string", - }, - }, - if: { - properties: { - descriptor: { - properties: { code: { const: "INCOTERMS" } }, - }, - }, - }, - then: { - properties: { - value: { - enum: [ - "DPU", - "CIF", - "EXW", - "FOB", - "DAP", - "DDP", - ], - }, - }, - }, - required: ["descriptor", "value"], - }, - }, - }, - required: ["descriptor", "list"], - }, - }, }, - required: ["stops"], + required: ["id","type","stops"], }, }, payments: { diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js index ff7b510..952d783 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onConfirmSchema.js @@ -214,7 +214,7 @@ module.exports = { required: ["label", "duration", "timestamp"], }, }, - required: ["id", "category_id", "descriptor","time","fulfillment_id"], + required: ["id", "category_id", "descriptor","fulfillment_id"], }, }, quote: { diff --git a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js index 1017c08..8591436 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/logistics_api_json_schema/v1.2/onStatusSchema.js @@ -795,7 +795,7 @@ module.exports = { const: { $data: "/confirm/0/message/order/created_at", }, - errorMessage: "mismatches in /confirm and /on_update", + errorMessage: "mismatches in /confirm and /on_status", }, updated_at: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js index 32ee952..cc4f494 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js @@ -43,7 +43,7 @@ const checkOnSearch = async (data, msgIdSet) => { if (!match) { onSrchObj[ "bpp/provider:location:" + id + ":RGC" - ] = `Reverse Geocoding for location ID ${id} failed. Area Code ${area_code} not matching with ${lat},${long} Lat-Long pair.`; + ] = `Reverse Geocoding for location ID ${id} failed for provider with id '${provider?.id}'. Area Code ${area_code} not matching with ${lat},${long} Lat-Long pair.`; } } catch (error) { console.log("bpp/providers error: ", error); @@ -56,6 +56,7 @@ const checkOnSearch = async (data, msgIdSet) => { provider.items.forEach((item) => { let itemTags = item?.tags; let mandatoryAttr; + let attrPresent = false; if (domain === "ONDC:RET12") { mandatoryAttr = constants.FASHION_ATTRIBUTES; @@ -64,11 +65,12 @@ const checkOnSearch = async (data, msgIdSet) => { mandatoryAttr = constants.ELECTRONICS_ATTRIBUTES; } itemTags.map(({ descriptor, list }, index) => { - switch (descriptor.code) { + switch (descriptor?.code) { case "attribute": + attrPresent = true; const encounteredAttr = []; list.map(({ descriptor, value }) => { - encounteredAttr.push(descriptor.code); + encounteredAttr.push(descriptor?.code); }); // Check if all mandatory attributes are encountered @@ -81,6 +83,12 @@ const checkOnSearch = async (data, msgIdSet) => { break; } }); + + if ( + (domain === "ONDC:RET12" || domain === "ONDC:RET14") && + !attrPresent + ) + onSrchObj.attrErr = `code = 'attribute' is required in items/tags for domain - ${domain} and provider/id - ${provider.id}`; }); } } diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js index 726d5fa..a8c8112 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js @@ -16,42 +16,45 @@ const checkSearch = async (data, msgIdSet) => { let startLocation, endLocation; stops.forEach((stop) => { if (stop.type === "start") { - startLocation = stop.location; + startLocation = stop?.location; } if (stop.type === "end") { - endLocation = stop.location; + endLocation = stop?.location; } }); - console.log("Checking Reverse Geocoding for `end` location in `fullfilment`"); - try { - const [lat, long] = endLocation.gps.split(","); - const area_code = endLocation.area_code; - const match = await reverseGeoCodingCheck(lat, long, area_code); - if (!match) - srchObj[ - "RGC-end-Err" - ] = `Reverse Geocoding for \`end\` failed. Area Code ${area_code} not matching with ${lat},${long} Lat-Long pair.`; - } catch (error) { - console.log("Error in end location", error); - } - - // check for context cityCode and fulfillment end location - try { - const pinToStd = JSON.parse( - fs.readFileSync(path.join(__dirname, "pinToStd.json"), "utf8") + if (endLocation) { + console.log( + "Checking Reverse Geocoding for `end` location in `fullfilment`" ); - const stdCode = data.context?.location?.city?.code.split(":")[1]; - const area_code = endLocation?.area_code; - if (pinToStd[area_code] && pinToStd[area_code] != stdCode) { - srchObj[ - "CityCode-Err" - ] = `CityCode ${stdCode} should match the city for the fulfillment end location ${area_code}, ${pinToStd[area_code]}`; + try { + const [lat, long] = endLocation?.gps.split(","); + const area_code = endLocation?.area_code; + const match = await reverseGeoCodingCheck(lat, long, area_code); + if (!match) + srchObj[ + "RGC-end-Err" + ] = `Reverse Geocoding for \`end\` failed. Area Code ${area_code} not matching with ${lat},${long} Lat-Long pair.`; + } catch (error) { + console.log("Error in end location", error); } - } catch (err) { - console.error("Error in city code check: ", err.message); - } + // check for context cityCode and fulfillment end location + try { + const pinToStd = JSON.parse( + fs.readFileSync(path.join(__dirname, "pinToStd.json"), "utf8") + ); + const stdCode = data.context?.location?.city?.code.split(":")[1]; + const area_code = endLocation?.area_code; + if (pinToStd[area_code] && pinToStd[area_code] != stdCode) { + srchObj[ + "CityCode-Err" + ] = `CityCode ${stdCode} should match the city for the fulfillment end location ${area_code}, ${pinToStd[area_code]}`; + } + } catch (err) { + console.error("Error in city code check: ", err.message); + } + } dao.setValue("searchObj", search); return srchObj; }; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logOnInit.js b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logOnInit.js index d53e7f6..7f94086 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logOnInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logOnInit.js @@ -14,9 +14,9 @@ const checkOnInit = (data, msgIdSet) => { let onSearchProvArr = dao.getValue("providersArr"); - console.log(dao.getValue("providerLoc"),on_init.provider_location); - if(dao.getValue("providerLoc")===false && on_init.provider_location){ - onInitObj.prvdrLocErr=`Provider location should be provided only if returned in /on_search, also it is used where the shipment has to be dropped at LSP location` + console.log(dao.getValue("providerLoc"), on_init.provider_location); + if (dao.getValue("providerLoc") === false && on_init.provider_location) { + onInitObj.prvdrLocErr = `Provider location should be provided only if returned in /on_search, also it is used where the shipment has to be dropped at LSP location`; } try { @@ -28,6 +28,7 @@ const checkOnInit = (data, msgIdSet) => { onInitObj.qteDecimalErr = `Quote price value should not have more than 2 decimal places`; } let totalBreakup = 0; + let tax_present = false; on_init.quote.breakup.forEach((breakup, i) => { if (!utils.hasTwoOrLessDecimalPlaces(breakup.price.value)) { let itemkey = `itemPriceErr${i}`; @@ -36,8 +37,8 @@ const checkOnInit = (data, msgIdSet) => { itemkey ] = `Price value for '${breakup["@ondc/org/title_type"]}' should not have more than 2 decimal places`; } - totalBreakup += parseFloat(breakup.price.value); - + totalBreakup += parseFloat(breakup?.price?.value); + if (breakup["@ondc/org/title_type"] === "tax") tax_present = true; onSearchProvArr?.forEach((provider) => { if (provider.id === provId) { provider?.items.forEach((item, i) => { @@ -51,7 +52,7 @@ const checkOnInit = (data, msgIdSet) => { ) { let itemKey = `priceArr${i}`; onInitObj[itemKey] = `Quote price ${parseFloat( - on_init.quote.price.value + on_init?.quote?.price?.value )} for item id '${ breakup["@ondc/org/item_id"] }' does not match item price ${ @@ -64,7 +65,9 @@ const checkOnInit = (data, msgIdSet) => { }); }); - if (parseFloat(on_init.quote.price.value) !== totalBreakup) + if (!tax_present) + onInitObj.taxErr = `fulfillment charges will have separate quote line item for taxes`; + if (parseFloat(on_init?.quote?.price?.value) !== totalBreakup) onInitObj.quotePriceErr = `Quote price ${parseFloat( on_init.quote.price.value )} does not match the breakup total ${totalBreakup} in ${ From 6eadb8ae1056d3c8e601fb990a0a9834a70e122a Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Wed, 17 Jan 2024 14:14:32 +0530 Subject: [PATCH 3/8] added b2b validations --- .../schema/B2B_json_schema/v1/on_select.js | 2 +- .../schema/B2B_json_schema/v2/confirm.js | 1 + .../schema/B2B_json_schema/v2/init.js | 1 + .../schema/B2B_json_schema/v2/on_confirm.js | 3 + .../schema/B2B_json_schema/v2/on_init.js | 6 +- .../schema/B2B_json_schema/v2/on_select.js | 50 +++++++------- .../schema/B2B_json_schema/v2/on_status.js | 2 + .../schema/B2B_json_schema/v2/select.js | 2 + .../utils/ContextVal.js | 1 - .../utils/b2b/b2bConfirm.js | 35 ++++++++++ .../utils/b2b/b2bOnInit.js | 35 ++++++++++ .../utils/b2b/b2bOnSelect.js | 66 +++++++++++++++++++ .../utils/b2b/b2bOnStatus.js | 37 +++++++---- .../utils/b2b/b2bSearch.js | 17 +++++ .../utils/b2b/msgValidator.js | 14 ++-- 15 files changed, 222 insertions(+), 50 deletions(-) create mode 100644 utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v1/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v1/on_select.js index f2fe7b0..41d3d59 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v1/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v1/on_select.js @@ -164,7 +164,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["Serviceable", "Non-Serviceable"], + enum: ["Serviceable", "Non-serviceable"], }, }, required: ["code"], diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js index 409f3ef..11543ea 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js @@ -634,6 +634,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, }, collected_by: { type: "string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js index 47ab2d3..6f969ba 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js @@ -487,6 +487,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, }, collected_by:{ type:"string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js index 9851d51..e083acc 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js @@ -661,6 +661,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, }, collected_by: { type: "string", @@ -668,9 +669,11 @@ module.exports = { }, "@ondc/org/buyer_app_finder_fee_type": { type: "string", + const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_type" }, }, "@ondc/org/buyer_app_finder_fee_amount": { type: "string", + const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_amount" }, }, "@ondc/org/settlement_details": { type: "array", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js index 6c72c5a..311aa99 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js @@ -583,6 +583,8 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, + }, collected_by: { type: "string", @@ -674,8 +676,6 @@ module.exports = { if: { properties: { collected_by: { const: "BAP" } } }, then: { required: [ - "params", - "status", "type", "collected_by", "@ondc/org/buyer_app_finder_fee_type", @@ -688,8 +688,6 @@ module.exports = { }, else: { required: [ - "params", - "status", "type", "collected_by", "@ondc/org/buyer_app_finder_fee_type", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js index d10a53e..f63f43a 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js @@ -112,10 +112,27 @@ module.exports = { id: { type: "string", const: { $data: "/select/0/message/order/provider/id" }, - }, + locations: { + type: "array", + items: { + type: "object", + properties: { + id: { + type: "string", + const: { + $data: + "/select/0/message/order/provider/locations/0/id", + }, + }, + }, + additionalProperties:false, + required: ["id"], + }, + } }, - required: ["id"], + additionalProperties:false, + required: ["id","locations"], }, items: { type: "array", @@ -164,7 +181,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["Serviceable", "Non-Serviceable"], + enum: ["Serviceable", "Non-serviceable"], }, }, required: ["code"], @@ -237,30 +254,6 @@ module.exports = { item: { type: "object", properties: { - quantity: { - type: "object", - properties: { - available: { - type: "object", - properties: { - count: { - type: "string", - }, - }, - required: ["count"], - }, - maximum: { - type: "object", - properties: { - count: { - type: "string", - }, - }, - required: ["count"], - }, - }, - required: ["available", "maximum"], - }, price: { type: "object", properties: { @@ -274,7 +267,7 @@ module.exports = { required: ["currency", "value"], }, }, - required: ["quantity", "price"], + required: ["price"], }, }, if: { @@ -336,6 +329,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, }, collected_by:{ type:"string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js index be80d41..24ad2b9 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js @@ -626,9 +626,11 @@ module.exports = { }, "@ondc/org/buyer_app_finder_fee_type": { type: "string", + const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_type" }, }, "@ondc/org/buyer_app_finder_fee_amount": { type: "string", + const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_amount" }, }, "@ondc/org/settlement_details": { type: "array", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index 4cc3b84..1ed6d8f 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -301,6 +301,7 @@ module.exports = { required: ["person"], }, }, + additionalProperties:false, required: ["id","type","stops"], }, }, @@ -316,6 +317,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], + const: { $data: "/search/0/message/intent/payment/type" }, }, }, required: ["type"], diff --git a/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js b/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js index 8749ce0..8c7731d 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/ContextVal.js @@ -95,7 +95,6 @@ const checkContextVal = (payload, msgIdSet, i) => { Obj.tmpstmpErr = `Timestamp mismatch for /${action} `; } else { if ( - action === "on_search" || action === "on_select" || action === "on_init" || action === "on_confirm" || diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index e69de29..d078f84 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -0,0 +1,35 @@ +const _ = require("lodash"); +const dao = require("../../dao/dao"); +const constants = require("../constants"); +const utils = require("../utils"); + +const checkConfirm = async (data, msgIdSet) => { + const cnfrmObj = {}; + let confirm = data; + confirm = confirm.message.order; + let payments = confirm?.payments; + + try { + console.log(`Checking payment object in /confirm api`); + payments.forEach(payment => { + let feeType = payment["@ondc/org/buyer_app_finder_fee_type"] + let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"] + + if(feeType!=dao.getValue("BuyerFinderFeeType")){ + cnfrmObj.feeTypeErr=`Buyer Finder Fee type mismatches from /search` + } + if(feeAmount!=dao.getValue("BuyerFinderFeeAmount")){ + cnfrmObj.feeTypeErr=`Buyer Finder Fee amount mismatches from /search` + } + + }); + } catch (error) { + console.log( + `!!Error while checking providers array in /on_search api`, + error + ); + } + + return cnfrmObj; +}; +module.exports = checkConfirm; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js index e69de29..c94f90e 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js @@ -0,0 +1,35 @@ +const _ = require("lodash"); +const dao = require("../../dao/dao"); +const constants = require("../constants"); +const utils = require("../utils"); + +const checkOnInit = async (data, msgIdSet) => { + const onInitObj = {}; + let onInit = data; + onInit = onInit.message.order; + let payments = onInit?.payments; + + try { + console.log(`Checking payment object in /on_init api`); + payments.forEach(payment => { + let feeType = payment["@ondc/org/buyer_app_finder_fee_type"] + let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"] + + if(feeType!=dao.getValue("BuyerFinderFeeType")){ + onInitObj.feeTypeErr=`Buyer Finder Fee type mismatches from /search` + } + if(feeAmount!=dao.getValue("BuyerFinderFeeAmount")){ + onInitObj.feeTypeErr=`Buyer Finder Fee amount mismatches from /search` + } + + }); + } catch (error) { + console.log( + `!!Error while checking providers array in /on_search api`, + error + ); + } + + return onInitObj; +}; +module.exports = checkOnInit; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js new file mode 100644 index 0000000..1cb2b9e --- /dev/null +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js @@ -0,0 +1,66 @@ +const _ = require("lodash"); +const dao = require("../../dao/dao"); +const constants = require("../constants"); +const utils = require("../utils"); + +const checkOnSelect = async (data, msgIdSet) => { + const onSelectObj = {}; + let onSelect = data; + onSelect = onSelect.message.order; + let quote = onSelect?.quote; + let fulfillments = onSelect?.fulfillments; + let ffState, ffId; + let deliveryQuoteItem = false; + try { + console.log("Checking fulfillment object in /on_select"); + if (fulfillments) { + fulfillments.forEach((fulfillment) => { + ffId = fulfillment?.id; + ffState = fulfillment?.state?.descriptor?.code; + }); + } + } catch (error) { + console.log(error); + } + + try { + console.log(`Checking quote object in /on_select api`); + quote?.breakup.forEach((breakup) => { + let itemPrice = parseFloat(breakup?.item?.price?.value); + let quantity = breakup["@ondc/org/item_quantity"]; + + if ( + breakup["@ondc/org/title_type"] === "delivery" && + breakup["@ondc/org/item_id"] === ffId + ) { + deliveryQuoteItem = true; + } + if ( + breakup["@ondc/org/title_type"] === "item" && + quantity && + parseFloat(breakup.price.value) != itemPrice * quantity?.count + ) { + onSelectObj.quoteErr = `Total price of the item with item id ${breakup["@ondc/org/item_id"]} is not in sync with the unit price and quantity`; + } + }); + + if (!deliveryQuoteItem && ffState === "Serviceable") { + onSelectObj.deliveryQuoteErr = `Delivery charges should be provided in quote/breakup when fulfillment is 'Serviceable'`; + } + if (deliveryQuoteItem && ffState === "Non-serviceable") { + onSelectObj.deliveryQuoteErr = `Delivery charges are not required in quote/breakup when fulfillment is 'Non-serviceable'`; + } + + if (ffState === "Non-serviceable" && !data.error) { + onSelectObj.nonSrvcableErr = `Error object with appropriate error code should be sent in case fulfillment is 'Non-serviceable`; + } + } catch (error) { + console.log( + `!!Error while checking providers array in /on_search api`, + error + ); + } + + return onSelectObj; +}; +module.exports = checkOnSelect; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js index 30585b6..9d12cef 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js @@ -15,6 +15,28 @@ const checkOnStatus = (data, msgIdSet) => { let items = on_status.items; let fulfillments = on_status.fulfillments; let pickupTime, deliveryTime, RtoPickupTime, RtoDeliveredTime; + let payments = on_status?.payments; + + try { + console.log(`Checking payment object in /on_status`); + payments.forEach((payment) => { + let paymentStatus = payment?.status; + let paymentType = payment?.type; + let params = payment?.params; + + if (paymentStatus === "PAID" && !params?.transaction_id) { + onStatusObj.pymntErr = `Transaction ID in payments/params is required when the payment status is 'PAID'`; + } + if (paymentStatus === "NOT-PAID" && params?.transaction_id) { + onStatusObj.pymntErr = `Transaction ID in payments/params cannot be provided when the payment status is 'NOT-PAID'`; + } + if(paymentType==='ON-FULFILLMENT' && orderState!='Completed' && paymentStatus==='PAID'){ + onStatusObj.pymntstsErr= `Payment status will be 'PAID' once the order is 'Completed' for payment type 'ON-FULFILLMENT'` + } + }); + } catch (error) { + console.log(error); + } // try { // console.log( @@ -98,7 +120,6 @@ const checkOnStatus = (data, msgIdSet) => { }); } - //Out-for-delivery if (ffState === "Out-for-delivery") { if (orderState !== "In-progress") { @@ -107,13 +128,12 @@ const checkOnStatus = (data, msgIdSet) => { fulfillment.stops.forEach((stop) => { if (stop.type === "start") { pickupTime = stop?.time?.timestamp; - + if (!pickupTime) { onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) is required for fulfillment state - ${ffState}`; } else if ( dao.getValue("pickupTime") && - pickupTime !== - dao.getValue("pickupTime") + pickupTime !== dao.getValue("pickupTime") ) { onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) cannot change for fulfillment state - ${ffState}`; } @@ -139,8 +159,7 @@ const checkOnStatus = (data, msgIdSet) => { onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) is required for fulfillment state - ${ffState}`; } else if ( dao.getValue("pickupTime") && - pickupTime !== - dao.getValue("pickupTime") + pickupTime !== dao.getValue("pickupTime") ) { onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) cannot change for fulfillment state - ${ffState}`; } @@ -149,7 +168,7 @@ const checkOnStatus = (data, msgIdSet) => { if (stop.type === "end") { deliveryTime = stop?.time?.timestamp; dao.setValue("deliveryTime", deliveryTime); - + if (!deliveryTime) { onStatusObj.deliveryTimeErr = `Delivery timestamp (fulfillments/end/time/timestamp) is required for fulfillment state - ${ffState}`; } @@ -162,10 +181,6 @@ const checkOnStatus = (data, msgIdSet) => { } }); } - - - - } }); } catch (error) { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js index a8c8112..a171cde 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSearch.js @@ -12,6 +12,23 @@ const checkSearch = async (data, msgIdSet) => { let contextTime = search.context.timestamp; search = search.message.intent; + try { + console.log("Checking buyer app finder fee in /search"); + + search.tags.forEach((tag) => { + if (tag?.descriptor?.code === "bap_terms" && tag?.list) { + tag.list.forEach((val) => { + if (val?.descriptor?.code === "finder_fee_type") { + dao.setValue("buyerFinderFeeType", val?.value); + } + if (val?.descriptor?.code === "finder_fee_amount") { + dao.setValue("buyerFinderFeeAmount", val?.value); + } + }); + } + }); + } catch (error) {} + const stops = data?.message?.intent?.fulfillment?.stops; let startLocation, endLocation; stops.forEach((stop) => { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js index e15deca..ae9f2dc 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js @@ -1,7 +1,8 @@ const checkConfirm = require("./b2bConfirm"); const checkInit = require("./b2bInit"); -const checkOnConfirm = require("./b2bOnConfirm"); const checkOnInit = require("./b2bOnInit"); +const checkOnConfirm = require("./b2bOnConfirm"); +const checkOnSelect = require("./b2bOnSelect"); const checkOnSearch = require("./b2bOnSearch"); const checkOnUpdate = require("./b2bOnUpdate"); const checkUpdate = require("./b2bUpdate"); @@ -18,14 +19,17 @@ const b2bVal = (element, action, msgIdSet) => { case "on_search": return checkOnSearch(element, msgIdSet); + case "on_select": + return checkOnSelect(element, msgIdSet); + case "init": return checkInit(element, msgIdSet); - // case "on_init": - // return checkOnInit(element, msgIdSet); + case "on_init": + return checkOnInit(element, msgIdSet); - // case "confirm": - // return checkConfirm(element, msgIdSet); + case "confirm": + return checkConfirm(element, msgIdSet); // case "on_confirm": // return checkOnConfirm(element, msgIdSet); From 4aa0f6727d42269062d187981e307af22a37092f Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Thu, 18 Jan 2024 10:25:19 +0530 Subject: [PATCH 4/8] bug fix --- .../utils/b2b/b2bConfirm.js | 21 +++++++++---------- .../utils/b2b/b2bOnInit.js | 21 +++++++++---------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index d078f84..74c9580 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -11,18 +11,17 @@ const checkConfirm = async (data, msgIdSet) => { try { console.log(`Checking payment object in /confirm api`); - payments.forEach(payment => { - let feeType = payment["@ondc/org/buyer_app_finder_fee_type"] - let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"] + payments.forEach((payment) => { + let feeType = payment["@ondc/org/buyer_app_finder_fee_type"]; + let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"]; - if(feeType!=dao.getValue("BuyerFinderFeeType")){ - cnfrmObj.feeTypeErr=`Buyer Finder Fee type mismatches from /search` - } - if(feeAmount!=dao.getValue("BuyerFinderFeeAmount")){ - cnfrmObj.feeTypeErr=`Buyer Finder Fee amount mismatches from /search` - } - - }); + if (feeType != dao.getValue("buyerFinderFeeType")) { + onInitObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; + } + if (feeAmount != dao.getValue("buyerFinderFeeAmount")) { + onInitObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; + } + }); } catch (error) { console.log( `!!Error while checking providers array in /on_search api`, diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js index c94f90e..16f3439 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js @@ -11,18 +11,17 @@ const checkOnInit = async (data, msgIdSet) => { try { console.log(`Checking payment object in /on_init api`); - payments.forEach(payment => { - let feeType = payment["@ondc/org/buyer_app_finder_fee_type"] - let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"] + payments.forEach((payment) => { + let feeType = payment["@ondc/org/buyer_app_finder_fee_type"]; + let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"]; - if(feeType!=dao.getValue("BuyerFinderFeeType")){ - onInitObj.feeTypeErr=`Buyer Finder Fee type mismatches from /search` - } - if(feeAmount!=dao.getValue("BuyerFinderFeeAmount")){ - onInitObj.feeTypeErr=`Buyer Finder Fee amount mismatches from /search` - } - - }); + if (feeType != dao.getValue("buyerFinderFeeType")) { + onInitObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; + } + if (feeAmount != dao.getValue("buyerFinderFeeAmount")) { + onInitObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; + } + }); } catch (error) { console.log( `!!Error while checking providers array in /on_search api`, From bd3441fce138406fee1a331f5e1a232b93094893 Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Mon, 22 Jan 2024 13:23:16 +0530 Subject: [PATCH 5/8] added b2b val --- .../B2B_json_schema/keywords/confirm.js | 1 - .../schema/B2B_json_schema/v2/confirm.js | 9 +- .../schema/B2B_json_schema/v2/init.js | 4 +- .../schema/B2B_json_schema/v2/on_confirm.js | 3 +- .../schema/B2B_json_schema/v2/on_init.js | 21 ++- .../schema/B2B_json_schema/v2/on_select.js | 117 +++++++++++--- .../schema/B2B_json_schema/v2/on_status.js | 19 ++- .../schema/B2B_json_schema/v2/select.js | 5 +- .../utils/b2b/b2bConfirm.js | 4 +- .../utils/b2b/b2bOnInit.js | 4 +- .../utils/b2b/b2bOnSearch.js | 69 ++++----- .../utils/b2b/b2bOnSelect.js | 17 ++- .../utils/b2b/b2bSelect.js | 144 ++++++++++++++++++ .../utils/b2b/msgValidator.js | 4 + 14 files changed, 335 insertions(+), 86 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/confirm.js index 239d106..5e7963a 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/keywords/confirm.js @@ -3,7 +3,6 @@ module.exports = { const contextTime = data?.context?.timestamp; const created_at = data?.message?.order?.created_at; const updated_at = data?.message?.order?.updated_at; - console.log(contextTime,updated_at); if ( (created_at && created_at > contextTime) || (updated_at && updated_at > contextTime) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js index 11543ea..ceb53cb 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js @@ -634,7 +634,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, + const: { $data: "/select/0/message/order/payments/0/type" }, }, collected_by: { type: "string", @@ -793,15 +793,12 @@ module.exports = { }, created_at: { type: "string", - const: { $data: "3/context/timestamp" }, - errorMessage: - "does not match context timestamp - ${3/context/timestamp}", }, updated_at: { type: "string", - const: { $data: "3/context/timestamp" }, + const: { $data: "1/created_at" }, errorMessage: - "does not match context timestamp - ${3/context/timestamp}", + "does not match created_at timestamp - ${1/created_at}", }, }, additionalProperties: false, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js index 6f969ba..24c21ce 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js @@ -228,7 +228,7 @@ module.exports = { }, }, }, - required: ["id", "fulfillment_ids","quantity","tags",], + required: ["id", "fulfillment_ids","quantity"], }, }, billing: { @@ -487,7 +487,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, + const: { $data: "/select/0/message/order/payments/0/type" }, }, collected_by:{ type:"string", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js index e083acc..21b1007 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js @@ -661,7 +661,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, + const: { $data: "/select/0/message/order/payments/0/type" }, }, collected_by: { type: "string", @@ -829,5 +829,6 @@ module.exports = { required: ["order"], }, }, + isFutureDated: true, required: ["context", "message"], }; diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js index 311aa99..6c7d5fc 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js @@ -287,13 +287,28 @@ module.exports = { properties: { id: { type: "string", + const: { $data: "/on_select/0/message/order/fulfillments/0/id" }, }, type: { type: "string", + const: { $data: "/on_select/0/message/order/fulfillments/0/type" }, + }, + "@ondc/org/provider_name": { + type: "string", + const: { $data: "/on_select/0/message/order/fulfillments/0/@ondc~1org~1provider_name" }, }, tracking: { type: "boolean", }, + "@ondc/org/category": { + type: "string", + const: { $data: "/on_select/0/message/order/fulfillments/0/@ondc~1org~1category" }, + }, + "@ondc/org/TAT": { + type: "string", + format: "duration", + const: { $data: "/on_select/0/message/order/fulfillments/0/@ondc~1org~1TAT" }, + }, stops: { type: "array", items: { @@ -459,6 +474,7 @@ module.exports = { }, value: { type: "string", + const: { $data: "/on_select/0/message/order/quote/price/value" }, }, }, required: ["currency", "value"], @@ -583,7 +599,7 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, + const: { $data: "/select/0/message/order/payments/0/type" }, }, collected_by: { @@ -680,9 +696,6 @@ module.exports = { "collected_by", "@ondc/org/buyer_app_finder_fee_type", "@ondc/org/buyer_app_finder_fee_amount", - "@ondc/org/settlement_basis", - "@ondc/org/settlement_window", - "@ondc/org/withholding_amount", "@ondc/org/settlement_details", ], }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js index f63f43a..8729009 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js @@ -58,7 +58,7 @@ module.exports = { type: "string", const: { $data: "/select/0/context/transaction_id" }, errorMessage: - "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", + "Transaction ID should be same across the transaction: ${/select/0/context/transaction_id}", }, message_id: { type: "string", @@ -75,14 +75,14 @@ module.exports = { errorMessage: "Message ID should not be equal to transaction_id: ${1/transaction_id}", }, - ] + ], }, timestamp: { type: "string", format: "date-time", }, ttl: { - type: "string" + type: "string", }, }, required: [ @@ -126,30 +126,98 @@ module.exports = { }, }, }, - additionalProperties:false, + additionalProperties: false, required: ["id"], }, - } + }, }, - additionalProperties:false, - required: ["id","locations"], + additionalProperties: false, + required: ["id", "locations"], }, items: { type: "array", items: { type: "object", properties: { + id: { + type: "string", + }, fulfillment_ids: { type: "array", items: { type: "string", }, }, - id: { - type: "string", + quantity: { + type: "object", + properties: { + selected: { + type: "object", + properties: { + count: { + type: "integer", + }, + }, + required: ["count"], + }, + }, + required: ["selected"], + }, + "add-ons": { + type: "array", + items: { + type: "object", + properties: { + id: { + type: "string", + }, + }, + required: ["id"], + }, + }, + tags: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: ["BUYER_TERMS"], + }, + }, + required: ["code"], + }, + list: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: ["ITEM_REQ", "PACKAGING_REQ"], + }, + }, + required: ["code"], + }, + value: { + type: "string", + }, + }, + required: ["descriptor", "value"], + }, + }, + }, + required: ["descriptor", "list"], + }, }, }, - required: ["id"], + required: ["id", "quantity", "fulfillment_ids"], }, }, fulfillments: { @@ -171,7 +239,7 @@ module.exports = { }, "@ondc/org/TAT": { type: "string", - format: "duration" + format: "duration", }, state: { type: "object", @@ -237,7 +305,14 @@ module.exports = { }, "@ondc/org/title_type": { type: "string", - enum: ["item", "discount", "packing", "delivery", "tax", "misc"] + enum: [ + "item", + "discount", + "packing", + "delivery", + "tax", + "misc", + ], }, price: { type: "object", @@ -310,11 +385,11 @@ module.exports = { }, ttl: { type: "string", - format: "duration" + format: "duration", }, }, isQuoteMatching: true, - + required: ["price", "breakup", "ttl"], }, payments: { @@ -329,18 +404,18 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, + const: { $data: "/select/0/message/order/payments/0/type" }, + }, + collected_by: { + type: "string", + enum: ["BAP", "BPP"], }, - collected_by:{ - type:"string", - enum:["BAP","BPP"] - } }, - required: ["type","collected_by"], + required: ["type", "collected_by"], }, }, }, - required: ["provider", "items", "quote","payments","fulfillments"], + required: ["provider", "items", "quote", "payments", "fulfillments"], }, }, required: ["order"], diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js index 24ad2b9..2f37c00 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_status.js @@ -243,7 +243,7 @@ module.exports = { "At-destination-hub", "Out-for-delivery", "Order-delivered", - "Cancelled" + "Cancelled", ], }, }, @@ -607,14 +607,15 @@ module.exports = { }, type: { type: "string", - const: { - $data: "/on_confirm/0/message/order/payments/0/type", - }, enum: [ "PRE-FULFILLMENT", "ON-FULFILLMENT", "POST-FULFILLMENT", ], + + const: { + $data: "/on_confirm/0/message/order/payments/0/type", + }, }, collected_by: { type: "string", @@ -626,11 +627,17 @@ module.exports = { }, "@ondc/org/buyer_app_finder_fee_type": { type: "string", - const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_type" }, + const: { + $data: + "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_type", + }, }, "@ondc/org/buyer_app_finder_fee_amount": { type: "string", - const: { $data: "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_amount" }, + const: { + $data: + "/confirm/0/message/order/payments/0/@ondc~1org~1buyer_app_finder_fee_amount", + }, }, "@ondc/org/settlement_details": { type: "array", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index 1ed6d8f..dae5330 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -124,7 +124,7 @@ module.exports = { format: "duration", }, }, - required: ["id", "locations","ttl"], + required: ["id", "locations"], }, items: { type: "array", @@ -215,7 +215,7 @@ module.exports = { }, }, }, - required: ["id", "location_ids", "quantity","tags","fulfillment_ids"], + required: ["id", "location_ids", "quantity","fulfillment_ids"], }, }, fulfillments: { @@ -317,7 +317,6 @@ module.exports = { "ON-FULFILLMENT", "POST-FULFILLMENT", ], - const: { $data: "/search/0/message/intent/payment/type" }, }, }, required: ["type"], diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index 74c9580..eafad54 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -18,13 +18,13 @@ const checkConfirm = async (data, msgIdSet) => { if (feeType != dao.getValue("buyerFinderFeeType")) { onInitObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; } - if (feeAmount != dao.getValue("buyerFinderFeeAmount")) { + if (parseFloat(feeAmount) != parseFloat(dao.getValue("buyerFinderFeeAmount"))) { onInitObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; } }); } catch (error) { console.log( - `!!Error while checking providers array in /on_search api`, + `!!Error while checking providers array in /confirm api`, error ); } diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js index 16f3439..635c8f9 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnInit.js @@ -18,13 +18,13 @@ const checkOnInit = async (data, msgIdSet) => { if (feeType != dao.getValue("buyerFinderFeeType")) { onInitObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; } - if (feeAmount != dao.getValue("buyerFinderFeeAmount")) { + if (parseFloat(feeAmount) != parseFloat(dao.getValue("buyerFinderFeeAmount"))) { onInitObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; } }); } catch (error) { console.log( - `!!Error while checking providers array in /on_search api`, + `!!Error while checking providers array in /on_init api`, error ); } diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js index cc4f494..a6bfe43 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js @@ -52,44 +52,45 @@ const checkOnSearch = async (data, msgIdSet) => { } //checking mandatory attributes for fashion and electronics + if (domain === "ONDC:RET12" || domain === "ONDC:RET14") { + provider.items.forEach((item) => { + let itemTags = item?.tags; + let mandatoryAttr; + let attrPresent = false; - provider.items.forEach((item) => { - let itemTags = item?.tags; - let mandatoryAttr; - let attrPresent = false; + if (domain === "ONDC:RET12") { + mandatoryAttr = constants.FASHION_ATTRIBUTES; + } + if (domain === "ONDC:RET14") { + mandatoryAttr = constants.ELECTRONICS_ATTRIBUTES; + } + itemTags.map(({ descriptor, list }, index) => { + switch (descriptor?.code) { + case "attribute": + attrPresent = true; + const encounteredAttr = []; + list.map(({ descriptor, value }) => { + encounteredAttr.push(descriptor?.code); + }); - if (domain === "ONDC:RET12") { - mandatoryAttr = constants.FASHION_ATTRIBUTES; - } - if (domain === "ONDC:RET14") { - mandatoryAttr = constants.ELECTRONICS_ATTRIBUTES; - } - itemTags.map(({ descriptor, list }, index) => { - switch (descriptor?.code) { - case "attribute": - attrPresent = true; - const encounteredAttr = []; - list.map(({ descriptor, value }) => { - encounteredAttr.push(descriptor?.code); - }); + // Check if all mandatory attributes are encountered + const missingAttr = mandatoryAttr.filter( + (code) => !encounteredAttr.includes(code) + ); + if (missingAttr.length > 0) { + onSrchObj.mssngAttrErr = `'${missingAttr}' attribute/s required in items/tags for ${domain} domain`; + } + break; + } + }); - // Check if all mandatory attributes are encountered - const missingAttr = mandatoryAttr.filter( - (code) => !encounteredAttr.includes(code) - ); - if (missingAttr.length > 0) { - onSrchObj.mssngAttrErr = `'${missingAttr}' attribute/s required in items/tags for ${domain} domain`; - } - break; - } + if ( + (domain === "ONDC:RET12" || domain === "ONDC:RET14") && + !attrPresent + ) + onSrchObj.attrErr = `code = 'attribute' is required in items/tags for domain - ${domain} and provider/id - ${provider.id}`; }); - - if ( - (domain === "ONDC:RET12" || domain === "ONDC:RET14") && - !attrPresent - ) - onSrchObj.attrErr = `code = 'attribute' is required in items/tags for domain - ${domain} and provider/id - ${provider.id}`; - }); + } } } diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js index 1cb2b9e..b7f7717 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js @@ -25,10 +25,12 @@ const checkOnSelect = async (data, msgIdSet) => { try { console.log(`Checking quote object in /on_select api`); - quote?.breakup.forEach((breakup) => { + quote?.breakup.forEach((breakup,i) => { let itemPrice = parseFloat(breakup?.item?.price?.value); + let available = Number(breakup?.item?.quantity?.available?.count) let quantity = breakup["@ondc/org/item_quantity"]; + if ( breakup["@ondc/org/title_type"] === "delivery" && breakup["@ondc/org/item_id"] === ffId @@ -38,9 +40,16 @@ const checkOnSelect = async (data, msgIdSet) => { if ( breakup["@ondc/org/title_type"] === "item" && quantity && - parseFloat(breakup.price.value) != itemPrice * quantity?.count + parseFloat(breakup.price.value).toFixed(2) != parseFloat(itemPrice * quantity?.count).toFixed(2) ) { - onSelectObj.quoteErr = `Total price of the item with item id ${breakup["@ondc/org/item_id"]} is not in sync with the unit price and quantity`; + let item = `quoteErr${i}` + onSelectObj[item] = `Total price of the item with item id ${breakup["@ondc/org/item_id"]} is not in sync with the unit price and quantity`; + } + + if( breakup["@ondc/org/title_type"] === "item" && + quantity && quantity?.count>available){ + let item = `quoteErr${i}` + onSelectObj[item] = `@ondc/org/item_quantity for item with id ${breakup["@ondc/org/item_id"]} cannot be more than the available count (quantity/avaialble/count) in quote/breakup`; } }); @@ -56,7 +65,7 @@ const checkOnSelect = async (data, msgIdSet) => { } } catch (error) { console.log( - `!!Error while checking providers array in /on_search api`, + `!!Error while checking providers array in /on_select api`, error ); } diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js index e69de29..9fbfd6a 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js @@ -0,0 +1,144 @@ +const _ = require("lodash"); +const dao = require("../../dao/dao"); +const constants = require("../constants"); +const utils = require("../utils"); + +const checkSelect = async (data, msgIdSet) => { + const selectObj = {}; + let select = data; + select = select.message.order; + let itemIdList; + let fulfillments = select?.fulfillments; + + fulfillments.forEach(fulfillment => { + + const fulId= fulfillment?.id + const fulType = fulfillment?.type + + console.log("Checking if the fulfillment id and type in /select present in /on_search") + + + }); + + + //provider check + // try { + // console.log(`Comparing provider object in /select and /on_search`); + // if (select.provider) { + // onSearchitemsArr = dao.getValue(`${select.provider.id}itemsArr`); + // let providerObj = providersArr?.filter( + // (prov) => prov.id === select.provider.id + // ); + // if (!providerObj || providerObj?.length < 1) { + // selectObj.prvdrErr = `Provider with id '${select.provider.id}' does not exist in the catalog provided in /on_search`; + // } else { + // if ( + // (!select?.provider?.locations || + // select?.provider?.locations?.length < 1) && + // providerObj[0]?.locations?.length > 1 + // ) { + // selectObj.provLocErr = `Provider location is mandatory if provided in the catalog in /on_search`; + // } else if (select?.provider?.locations) { + // let providerLocArr = select.provider.locations; + // let providerLocExists = false; + // providerLocArr.forEach((location, i) => { + // providerObj[0]?.locations?.forEach((element) => { + // console.log(location.id, element.id); + + // if (location.id === element.id) providerLocExists = true; + // }); + + // if (!providerLocExists) { + // let itemkey = `providerLocErr${i}`; + // selectObj[ + // itemkey + // ] = `Provider location with id '${location.id}' does not exist in the catalog provided in /on_search`; + // } + // providerLocExists = false; + // }); + // } + // } + // } + // } catch (error) { + // console.log( + // `!!Error while checking provider object in /${constants.LOG_select}`, + // error + // ); + // } + + // //item check + // try { + // console.log(`Comparing item object in /select and /on_search`); + // let itemExists = false; + + // itemsArr?.forEach((item, i) => { + // if (item.descriptor.code === "P2H2P") { + // p2h2p = true; + // } + // onSearchitemsArr?.forEach((element) => { + // if (item.id === element.id) itemExists = true; + // }); + // if (!itemExists) { + // let itemkey = `itemErr${i}`; + // selectObj[ + // itemkey + // ] = `Item Id '${item.id}' does not exist in /on_search`; + // } else { + // let itemObj = onSearchitemsArr.filter( + // (element) => item.id === element.id + // ); + + // itemObj = itemObj[0]; + // dao.setValue("selectedItem", itemObj.id); + // console.log(itemObj.id); + // if (item.category_id != itemObj.category_id) { + // let itemkey = `catIdErr${i}`; + // selectObj[ + // itemkey + // ] = `Category id '${item.category_id}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; + // } + // if (item.descriptor.code != itemObj.descriptor.code) { + // let itemkey = `codeErr${i}`; + // selectObj[ + // itemkey + // ] = `Descriptor code '${item.descriptor.code}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; + // } + // fulfillmentsArr.forEach((fulfillment, i) => { + // if (fulfillment.id !== itemObj.fulfillment_id) { + // let itemkey = `flfillmentErr${i}`; + // selectObj[ + // itemkey + // ] = `Fulfillment id '${fulfillment.id}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; + // } else { + // let bppfulfillment = bppFulfillmentsArr?.find( + // (element) => element.id === fulfillment.id + // ); + // if (fulfillment.type !== bppfulfillment?.type) { + // let itemkey = `flfillmentTypeErr${i}`; + // selectObj[ + // itemkey + // ] = `Fulfillment type '${fulfillment.type}' for fulfillment id '${fulfillment.id}' does not match with the catalog provided in /on_search`; + // } + // } + // }); + // } + // itemExists = false; + // }); + // } catch (error) { + // console.log(error); + // } + // try { + // console.log("Checking fulfillment object in /select"); + // if (fulfillments) { + // fulfillments.forEach((fulfillment) => { + // ffId = fulfillment?.id; + // ffState = fulfillment?.state?.descriptor?.code; + // }); + // } + // } catch (error) { + // console.log(error); + // } + + return selectObj; +}; +module.exports = checkSelect; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js index ae9f2dc..ce96288 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/msgValidator.js @@ -1,5 +1,6 @@ const checkConfirm = require("./b2bConfirm"); const checkInit = require("./b2bInit"); +const checkSelect = require("./b2bSelect"); const checkOnInit = require("./b2bOnInit"); const checkOnConfirm = require("./b2bOnConfirm"); const checkOnSelect = require("./b2bOnSelect"); @@ -19,6 +20,9 @@ const b2bVal = (element, action, msgIdSet) => { case "on_search": return checkOnSearch(element, msgIdSet); + case "select": + return checkSelect(element, msgIdSet); + case "on_select": return checkOnSelect(element, msgIdSet); From 9918bd503579b8b1caec95147f394e2178a01449 Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Mon, 22 Jan 2024 15:56:15 +0530 Subject: [PATCH 6/8] updated --- .../schema/B2B_json_schema/v2/on_select.js | 65 ++++++++++++++++++ .../schema/B2B_json_schema/v2/select.js | 67 ++++++++++++++++++- .../utils/b2b/b2bConfirm.js | 26 ++++++- 3 files changed, 154 insertions(+), 4 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js index 8729009..309dd8f 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js @@ -257,6 +257,71 @@ module.exports = { }, required: ["descriptor"], }, + tags: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: ["DELIVERY_TERMS"], + }, + }, + required: ["code"], + }, + list: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: [ + "INCOTERMS", + "NAMED_PLACE_OF_DELIVERY", + ], + }, + }, + required: ["code"], + }, + value: { + type: "string", + }, + }, + if: { + properties: { + descriptor: { + properties: { code: { const: "INCOTERMS" } }, + }, + }, + }, + then: { + properties: { + value: { + enum: [ + "DPU", + "CIF", + "EXW", + "FOB", + "DAP", + "DDP", + ], + }, + }, + }, + required: ["descriptor", "value"], + }, + }, + }, + required: ["descriptor", "list"], + }, + }, }, required: [ "id", diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index dae5330..ced30ea 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -124,7 +124,7 @@ module.exports = { format: "duration", }, }, - required: ["id", "locations"], + required: ["id", "locations","ttl"], }, items: { type: "array", @@ -300,6 +300,71 @@ module.exports = { }, required: ["person"], }, + tags: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: ["DELIVERY_TERMS"], + }, + }, + required: ["code"], + }, + list: { + type: "array", + items: { + type: "object", + properties: { + descriptor: { + type: "object", + properties: { + code: { + type: "string", + enum: [ + "INCOTERMS", + "NAMED_PLACE_OF_DELIVERY", + ], + }, + }, + required: ["code"], + }, + value: { + type: "string", + }, + }, + if: { + properties: { + descriptor: { + properties: { code: { const: "INCOTERMS" } }, + }, + }, + }, + then: { + properties: { + value: { + enum: [ + "DPU", + "CIF", + "EXW", + "FOB", + "DAP", + "DDP", + ], + }, + }, + }, + required: ["descriptor", "value"], + }, + }, + }, + required: ["descriptor", "list"], + }, + }, }, additionalProperties:false, required: ["id","type","stops"], diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index eafad54..ed7ed39 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -14,12 +14,32 @@ const checkConfirm = async (data, msgIdSet) => { payments.forEach((payment) => { let feeType = payment["@ondc/org/buyer_app_finder_fee_type"]; let feeAmount = payment["@ondc/org/buyer_app_finder_fee_amount"]; + let paymentStatus = payment?.status; + let paymentType = payment?.type; + let params = payment?.params; if (feeType != dao.getValue("buyerFinderFeeType")) { - onInitObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; + cnfrmObj.feeTypeErr = `Buyer Finder Fee type mismatches from /search`; } - if (parseFloat(feeAmount) != parseFloat(dao.getValue("buyerFinderFeeAmount"))) { - onInitObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; + if ( + parseFloat(feeAmount) != + parseFloat(dao.getValue("buyerFinderFeeAmount")) + ) { + cnfrmObj.feeTypeErr = `Buyer Finder Fee amount mismatches from /search`; + } + + if (paymentStatus === "PAID" && !params?.transaction_id) { + cnfrmObj.pymntErr = `Transaction ID in payments/params is required when the payment status is 'PAID'`; + } + if (paymentStatus === "NOT-PAID" && params?.transaction_id) { + cnfrmObj.pymntErr = `Transaction ID in payments/params cannot be provided when the payment status is 'NOT-PAID'`; + } + if ( + paymentType === "ON-FULFILLMENT" && + orderState != "Completed" && + paymentStatus === "PAID" + ) { + cnfrmObj.pymntstsErr = `Payment status will be 'PAID' once the order is 'Completed' for payment type 'ON-FULFILLMENT'`; } }); } catch (error) { From 95b72a275d670e4934a2c244c7f32801cb037bfd Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Tue, 23 Jan 2024 16:19:45 +0530 Subject: [PATCH 7/8] added b2b checks --- .../schema/B2B_json_schema/v2/confirm.js | 7 +- .../schema/B2B_json_schema/v2/init.js | 7 +- .../schema/B2B_json_schema/v2/on_confirm.js | 6 +- .../schema/B2B_json_schema/v2/on_init.js | 7 +- .../schema/B2B_json_schema/v2/on_select.js | 8 +- .../schema/B2B_json_schema/v2/select.js | 11 +- .../utils/b2b/b2bConfirm.js | 18 ++ .../utils/b2b/b2bInit.js | 87 +------ .../utils/b2b/b2bOnSearch.js | 6 + .../utils/b2b/b2bOnSelect.js | 44 +++- .../utils/b2b/b2bOnStatus.js | 53 +++- .../utils/b2b/b2bSelect.js | 231 ++++++++---------- .../utils/constants.js | 3 +- .../utils/logistics/logInit.js | 2 +- .../log-verification-utility/utils/utils.js | 39 +++ 15 files changed, 302 insertions(+), 227 deletions(-) diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js index ceb53cb..6598048 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/confirm.js @@ -1,3 +1,4 @@ +const constants = require("../../../utils/constants"); module.exports = { $id: "http://example.com/schema/confirmSchema", type: "object", @@ -756,6 +757,7 @@ module.exports = { }, tags: { type: "array", + minItems: 3, items: { type: "object", properties: { @@ -763,7 +765,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id"], + enum: constants.TERMS }, }, }, @@ -776,7 +778,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id_code", "buyer_id_no"], + enum: constants.B2B_BPP_TERMS }, }, }, @@ -813,6 +815,7 @@ module.exports = { "payments", "created_at", "updated_at", + "tags" ], }, }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js index 24c21ce..70d6924 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/init.js @@ -1,3 +1,5 @@ +const constants = require("../../../utils/constants"); + module.exports = { $id: "http://example.com/schema/initSchema", type: "object", @@ -499,6 +501,7 @@ module.exports = { }, tags: { type: "array", + minItems: 1, items: { type: "object", properties: { @@ -506,7 +509,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id"], + enum: constants.TERMS }, }, }, @@ -519,7 +522,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id_code", "buyer_id_no"], + enum: constants.B2B_BPP_TERMS }, }, }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js index 21b1007..97cf393 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_confirm.js @@ -1,3 +1,4 @@ +const constants = require("../../../utils/constants"); module.exports = { $id: "http://example.com/schema/onConfirmSchema", type: "object", @@ -763,6 +764,7 @@ module.exports = { }, tags: { type: "array", + minItems: 3, items: { type: "object", properties: { @@ -770,7 +772,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id"], + enum: constants.TERMS }, }, }, @@ -783,7 +785,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id_code", "buyer_id_no"], + enum: constants.B2B_BPP_TERMS }, }, }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js index 6c7d5fc..7095ff1 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_init.js @@ -1,3 +1,4 @@ +const constants = require("../../../utils/constants"); module.exports = { $id: "http://example.com/schema/onInitSchema", type: "object", @@ -714,6 +715,7 @@ module.exports = { }, tags: { type: "array", + minItems: 2, items: { type: "object", properties: { @@ -721,7 +723,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id"], + enum: constants.TERMS }, }, }, @@ -734,7 +736,7 @@ module.exports = { properties: { code: { type: "string", - enum: ["buyer_id_code", "buyer_id_no"], + enum: constants.B2B_BPP_TERMS }, }, }, @@ -759,6 +761,7 @@ module.exports = { "fulfillments", "quote", "payments", + "tags" ], }, }, diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js index 309dd8f..fd73c5e 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/on_select.js @@ -480,7 +480,13 @@ module.exports = { }, }, }, - required: ["provider", "items", "quote", "payments", "fulfillments"], + required: [ + "provider", + "items", + "quote", + "payments", + "fulfillments" + ], }, }, required: ["order"], diff --git a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js index ced30ea..1652dfa 100644 --- a/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js +++ b/utilities/logistics-b2b/log-verification-utility/schema/B2B_json_schema/v2/select.js @@ -124,7 +124,7 @@ module.exports = { format: "duration", }, }, - required: ["id", "locations","ttl"], + required: ["id", "locations", "ttl"], }, items: { type: "array", @@ -215,7 +215,7 @@ module.exports = { }, }, }, - required: ["id", "location_ids", "quantity","fulfillment_ids"], + required: ["id", "location_ids", "quantity", "fulfillment_ids"], }, }, fulfillments: { @@ -244,7 +244,8 @@ module.exports = { type: "string", pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$", - errorMessage: "Incorrect gps value (minimum of six decimal places are required)", + errorMessage: + "Incorrect gps value (minimum of six decimal places are required)", }, area_code: { type: "string", @@ -366,8 +367,8 @@ module.exports = { }, }, }, - additionalProperties:false, - required: ["id","type","stops"], + additionalProperties: false, + required: ["id", "type", "stops"], }, }, payments: { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index ed7ed39..f02e68b 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -7,8 +7,26 @@ const checkConfirm = async (data, msgIdSet) => { const cnfrmObj = {}; let confirm = data; confirm = confirm.message.order; + let orderState = confirm.state; let payments = confirm?.payments; + let items = confirm.items; + const selectedItems = dao.getValue("slctdItemsArray"); + + try { + console.log("Comparing items object with /select"); + const itemDiff = utils.findDifferencesInArrays(items, selectedItems); + console.log(itemDiff); + itemDiff.forEach((item, i) => { + let itemkey = `item-${i}-DiffErr`; + cnfrmObj[ + itemkey + ] = `In /items, '${item.attributes}' mismatch from /select`; + }); + } catch (error) { + console.log(error); + } + try { console.log(`Checking payment object in /confirm api`); payments.forEach((payment) => { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js index b7cc0ce..f201555 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js @@ -8,86 +8,21 @@ const checkInit = (data, msgIdSet) => { let init = data; init = init.message.order; - let itemsArr = init.items; - let fulfillmentsArr = init.fulfillments; - let onSearchitemsArr; - let providersArr = dao.getValue("providersArr"); + let items = init.items; + const selectedItems = dao.getValue("slctdItemsArray"); - //provider check try { - console.log(`Comparing provider object in /init and /on_search`); - if (init.provider) { - onSearchitemsArr = dao.getValue(`${init.provider.id}itemsArr`); - let providerObj = providersArr?.filter( - (prov) => prov.id === init.provider.id - ); - if (providerObj?.length < 1) { - initObj.prvdrErr = `Provider with id '${init.provider.id}' does not exist in the catalog provided in /on_search`; - } else { - if ( - (!init?.provider?.locations || - init?.provider?.locations?.length < 1) && - providerObj[0]?.locations?.length > 1 - ) { - initObj.provLocErr = `Provider location is mandatory if provided in the catalog in /on_search`; - } else if (init?.provider?.locations) { - let providerLocArr = init.provider.locations; - let providerLocExists = false; - - if (providerLocArr) { - providerLocArr.forEach((location, i) => { - if (providerObj) { - providerObj[0]?.locations?.forEach((element) => { - console.log(location.id, element.id); - - if (location.id === element.id) providerLocExists = true; - }); - } - - if (!providerLocExists) { - let itemkey = `providerLocErr${i}`; - initObj[ - itemkey - ] = `Provider location with id '${location.id}' does not exist in the catalog provided in /on_search`; - } - providerLocExists = false; - }); - } - } - } - } - } catch (error) { - console.log( - `!!Error while checking provider object in /${constants.LOG_INIT}`, - error - ); - } - - //item check - try { - console.log(`Comparing item object in /init and /on_search`); - let itemExists = false; - - itemsArr.forEach((item, i) => { - if (onSearchitemsArr) { - onSearchitemsArr.forEach((element) => { - if (item.id === element.id) itemExists = true; - }); - } - - if (!itemExists) { - let itemkey = `itemErr${i}`; - initObj[itemkey] = `Item Id '${item.id}' does not exist in /on_search`; - } else { - let itemObj = onSearchitemsArr.filter( - (element) => item.id === element.id - ); - itemObj = itemObj[0]; - } - itemExists = false; + console.log("Comparing items object with /select"); + const itemDiff = utils.findDifferencesInArrays(items, selectedItems); + console.log(itemDiff); + itemDiff.forEach((item, i) => { + let itemkey = `item-${i}-DiffErr`; + initObj[ + itemkey + ] = `In /items, '${item.attributes}' mismatch from /select`; }); } catch (error) { - console.log(`!!Error while checking items array in /on_init API`, error); + console.log(error); } return initObj; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js index a6bfe43..56bc22a 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSearch.js @@ -10,6 +10,12 @@ const checkOnSearch = async (data, msgIdSet) => { let domain = onSearch.context.domain; onSearch = onSearch.message.catalog; + //saving fulfillments + + const fulfillments = onSearch?.fulfillments; + + dao.setValue("fulfillmentsArr", fulfillments); + try { console.log(`Saving provider items array in /on_search api`); if (onSearch["providers"]) { diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js index b7f7717..f99599e 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js @@ -8,9 +8,11 @@ const checkOnSelect = async (data, msgIdSet) => { let onSelect = data; onSelect = onSelect.message.order; let quote = onSelect?.quote; + const items = onSelect.items; let fulfillments = onSelect?.fulfillments; let ffState, ffId; let deliveryQuoteItem = false; + const selectedItems = dao.getValue("slctdItemsArray"); try { console.log("Checking fulfillment object in /on_select"); if (fulfillments) { @@ -23,14 +25,28 @@ const checkOnSelect = async (data, msgIdSet) => { console.log(error); } + try { + console.log("Comparing items object with /select"); + const itemDiff = utils.findDifferencesInArrays(items, selectedItems); + console.log(itemDiff); + itemDiff.forEach((item, i) => { + let itemkey = `item-${i}-DiffErr`; + onSelectObj[ + itemkey + ] = `In /items, '${item.attributes}' mismatch from /select`; + }); + } catch (error) { + console.log(error); + } + + try { console.log(`Checking quote object in /on_select api`); - quote?.breakup.forEach((breakup,i) => { + quote?.breakup.forEach((breakup, i) => { let itemPrice = parseFloat(breakup?.item?.price?.value); - let available = Number(breakup?.item?.quantity?.available?.count) + let available = Number(breakup?.item?.quantity?.available?.count); let quantity = breakup["@ondc/org/item_quantity"]; - if ( breakup["@ondc/org/title_type"] === "delivery" && breakup["@ondc/org/item_id"] === ffId @@ -40,16 +56,24 @@ const checkOnSelect = async (data, msgIdSet) => { if ( breakup["@ondc/org/title_type"] === "item" && quantity && - parseFloat(breakup.price.value).toFixed(2) != parseFloat(itemPrice * quantity?.count).toFixed(2) + parseFloat(breakup.price.value).toFixed(2) != + parseFloat(itemPrice * quantity?.count).toFixed(2) ) { - let item = `quoteErr${i}` - onSelectObj[item] = `Total price of the item with item id ${breakup["@ondc/org/item_id"]} is not in sync with the unit price and quantity`; + let item = `quoteErr${i}`; + onSelectObj[ + item + ] = `Total price of the item with item id ${breakup["@ondc/org/item_id"]} is not in sync with the unit price and quantity`; } - if( breakup["@ondc/org/title_type"] === "item" && - quantity && quantity?.count>available){ - let item = `quoteErr${i}` - onSelectObj[item] = `@ondc/org/item_quantity for item with id ${breakup["@ondc/org/item_id"]} cannot be more than the available count (quantity/avaialble/count) in quote/breakup`; + if ( + breakup["@ondc/org/title_type"] === "item" && + quantity && + quantity?.count > available + ) { + let item = `quoteErr${i}`; + onSelectObj[ + item + ] = `@ondc/org/item_quantity for item with id ${breakup["@ondc/org/item_id"]} cannot be more than the available count (quantity/avaialble/count) in quote/breakup`; } }); diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js index 9d12cef..7d1817a 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnStatus.js @@ -30,8 +30,12 @@ const checkOnStatus = (data, msgIdSet) => { if (paymentStatus === "NOT-PAID" && params?.transaction_id) { onStatusObj.pymntErr = `Transaction ID in payments/params cannot be provided when the payment status is 'NOT-PAID'`; } - if(paymentType==='ON-FULFILLMENT' && orderState!='Completed' && paymentStatus==='PAID'){ - onStatusObj.pymntstsErr= `Payment status will be 'PAID' once the order is 'Completed' for payment type 'ON-FULFILLMENT'` + if ( + paymentType === "ON-FULFILLMENT" && + orderState != "Completed" && + paymentStatus === "PAID" + ) { + onStatusObj.pymntstsErr = `Payment status will be 'PAID' once the order is 'Completed' for payment type 'ON-FULFILLMENT'`; } }); } catch (error) { @@ -182,6 +186,51 @@ const checkOnStatus = (data, msgIdSet) => { }); } } + if (fulfillment.type === "Self-Pickup") { + if ( + ffState === "Pending" || + ffState === "Packed" + ) { + fulfillment.stops.forEach((stop) => { + if (stop.type === "start") { + if (stop?.time?.timestamp) { + onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) cannot be provided for fulfillment state - ${ffState}`; + } + } + + if (stop.type === "end") { + if (stop?.time?.timestamp) { + onStatusObj.deliveryTimeErr = `Delivery timestamp (fulfillments/end/time/timestamp) cannot be provided for fulfillment state - ${ffState}`; + } + } + }); + } + + if (ffState === "Order-picked-up") { + if (orderState !== "Completed") { + onStatusObj.ordrStatErr = `Order state should be 'Completed' once the order is picked up`; + } + fulfillment.stops.forEach((stop) => { + if (stop.type === "start") { + pickupTime = stop?.time?.timestamp; + dao.setValue("pickupTime", pickupTime); + if (!pickupTime) { + onStatusObj.pickupTimeErr = `Pickup timestamp (fulfillments/start/time/timestamp) is required for fulfillment state - ${ffState}`; + } + + if (_.gt(pickupTime, contextTime)) { + onStatusObj.tmstmpErr = `Pickup timestamp (fulfillments/start/time/timestamp) cannot be future dated w.r.t context/timestamp for fulfillment state - ${ffState}`; + } + } + + if (stop.type === "end") { + if (stop?.time?.timestamp) { + onStatusObj.deliveryTimeErr = `Delivery timestamp (fulfillments/end/time/timestamp) cannot be provided for fulfillment state - ${ffState}`; + } + } + }); + } + } }); } catch (error) { console.log(`Error checking fulfillments/start in /on_status`); diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js index 9fbfd6a..9a0539f 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bSelect.js @@ -7,137 +7,122 @@ const checkSelect = async (data, msgIdSet) => { const selectObj = {}; let select = data; select = select.message.order; - let itemIdList; let fulfillments = select?.fulfillments; - - fulfillments.forEach(fulfillment => { + let providersArr = dao.getValue("providersArr"); + let fulfillmentsArr = dao.getValue("fulfillmentsArr"); + let itemsArr = select.items; + dao.setValue("slctdItemsArray",itemsArr) - const fulId= fulfillment?.id - const fulType = fulfillment?.type + // provider check + try { + console.log(`Comparing provider object in /select and /on_search`); + if (select.provider) { + onSearchitemsArr = dao.getValue(`${select.provider.id}itemsArr`); + let providerObj = providersArr?.filter( + (prov) => prov.id === select.provider.id + ); + if (!providerObj || providerObj?.length < 1) { + selectObj.prvdrErr = `Provider with id '${select.provider.id}' does not exist in the catalog provided in /on_search`; + } else { + if ( + (!select?.provider?.locations || + select?.provider?.locations?.length < 1) && + providerObj[0]?.locations?.length > 1 + ) { + selectObj.provLocErr = `Provider location is mandatory if provided in the catalog in /on_search`; + } else if (select?.provider?.locations) { + let providerLocArr = select.provider.locations; + let providerLocExists = false; + providerLocArr.forEach((location, i) => { + providerObj[0]?.locations?.forEach((element) => { + console.log(location.id, element.id); - console.log("Checking if the fulfillment id and type in /select present in /on_search") - - - }); + if (location.id === element.id) providerLocExists = true; + }); + if (!providerLocExists) { + let itemkey = `providerLocErr${i}`; + selectObj[ + itemkey + ] = `Provider location with id '${location.id}' does not exist in the catalog provided in /on_search`; + } + providerLocExists = false; + }); + } + } + } + } catch (error) { + console.log( + `!!Error while checking provider object in /${constants.LOG_select}`, + error + ); + } - //provider check - // try { - // console.log(`Comparing provider object in /select and /on_search`); - // if (select.provider) { - // onSearchitemsArr = dao.getValue(`${select.provider.id}itemsArr`); - // let providerObj = providersArr?.filter( - // (prov) => prov.id === select.provider.id - // ); - // if (!providerObj || providerObj?.length < 1) { - // selectObj.prvdrErr = `Provider with id '${select.provider.id}' does not exist in the catalog provided in /on_search`; - // } else { - // if ( - // (!select?.provider?.locations || - // select?.provider?.locations?.length < 1) && - // providerObj[0]?.locations?.length > 1 - // ) { - // selectObj.provLocErr = `Provider location is mandatory if provided in the catalog in /on_search`; - // } else if (select?.provider?.locations) { - // let providerLocArr = select.provider.locations; - // let providerLocExists = false; - // providerLocArr.forEach((location, i) => { - // providerObj[0]?.locations?.forEach((element) => { - // console.log(location.id, element.id); + //item check + try { + console.log(`Comparing item object in /select and /on_search`); - // if (location.id === element.id) providerLocExists = true; - // }); + itemsArr?.forEach((item, i) => { + let itemExists = false; + onSearchitemsArr?.forEach((element) => { + if (item.id === element.id) itemExists = true; + }); + if (!itemExists) { + let itemkey = `itemErr${i}`; + selectObj[ + itemkey + ] = `Item Id '${item.id}' does not exist in /on_search`; + } else { + let itemObj = onSearchitemsArr.filter( + (element) => element.id === item.id + ); - // if (!providerLocExists) { - // let itemkey = `providerLocErr${i}`; - // selectObj[ - // itemkey - // ] = `Provider location with id '${location.id}' does not exist in the catalog provided in /on_search`; - // } - // providerLocExists = false; - // }); - // } - // } - // } - // } catch (error) { - // console.log( - // `!!Error while checking provider object in /${constants.LOG_select}`, - // error - // ); - // } + itemObj = itemObj[0]; + // dao.setValue("selectedItem", itemObj.id); + console.log(itemObj.id); + if ( + !_.every(item.fulfillment_ids, (element) => + _.includes(itemObj.fulfillment_ids, element) + ) + ) { + let itemkey = `flflmntIdErr${i}`; + selectObj[ + itemkey + ] = `Fulfillment ids for item with id '${item.id}' does not match with the catalog provided in /on_search`; + } + if ( + !_.every(item.location_ids, (element) => + _.includes(itemObj.location_ids, element) + ) + ) { + let itemkey = `lctnIdErr${i}`; + selectObj[ + itemkey + ] = `Location ids for item with id '${item.id}' does not match with the catalog provided in /on_search`; + } - // //item check - // try { - // console.log(`Comparing item object in /select and /on_search`); - // let itemExists = false; - - // itemsArr?.forEach((item, i) => { - // if (item.descriptor.code === "P2H2P") { - // p2h2p = true; - // } - // onSearchitemsArr?.forEach((element) => { - // if (item.id === element.id) itemExists = true; - // }); - // if (!itemExists) { - // let itemkey = `itemErr${i}`; - // selectObj[ - // itemkey - // ] = `Item Id '${item.id}' does not exist in /on_search`; - // } else { - // let itemObj = onSearchitemsArr.filter( - // (element) => item.id === element.id - // ); - - // itemObj = itemObj[0]; - // dao.setValue("selectedItem", itemObj.id); - // console.log(itemObj.id); - // if (item.category_id != itemObj.category_id) { - // let itemkey = `catIdErr${i}`; - // selectObj[ - // itemkey - // ] = `Category id '${item.category_id}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; - // } - // if (item.descriptor.code != itemObj.descriptor.code) { - // let itemkey = `codeErr${i}`; - // selectObj[ - // itemkey - // ] = `Descriptor code '${item.descriptor.code}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; - // } - // fulfillmentsArr.forEach((fulfillment, i) => { - // if (fulfillment.id !== itemObj.fulfillment_id) { - // let itemkey = `flfillmentErr${i}`; - // selectObj[ - // itemkey - // ] = `Fulfillment id '${fulfillment.id}' for item with id '${item.id}' does not match with the catalog provided in /on_search`; - // } else { - // let bppfulfillment = bppFulfillmentsArr?.find( - // (element) => element.id === fulfillment.id - // ); - // if (fulfillment.type !== bppfulfillment?.type) { - // let itemkey = `flfillmentTypeErr${i}`; - // selectObj[ - // itemkey - // ] = `Fulfillment type '${fulfillment.type}' for fulfillment id '${fulfillment.id}' does not match with the catalog provided in /on_search`; - // } - // } - // }); - // } - // itemExists = false; - // }); - // } catch (error) { - // console.log(error); - // } - // try { - // console.log("Checking fulfillment object in /select"); - // if (fulfillments) { - // fulfillments.forEach((fulfillment) => { - // ffId = fulfillment?.id; - // ffState = fulfillment?.state?.descriptor?.code; - // }); - // } - // } catch (error) { - // console.log(error); - // } + //checking fulfillments + fulfillments.forEach((fulfillment, i) => { + let bppfulfillment = fulfillmentsArr?.find( + (element) => element.id === fulfillment.id + ); + if (!bppfulfillment) { + let itemkey = `flfillmentIDerr${i}`; + selectObj[ + itemkey + ] = `Fulfillment id '${fulfillment.id}' does not match with the catalog provided in /on_search`; + } else if (fulfillment.type !== bppfulfillment?.type) { + let itemkey = `flfillmentTypeErr${i}`; + selectObj[ + itemkey + ] = `Fulfillment type '${fulfillment.type}' for fulfillment id '${fulfillment.id}' does not match with the catalog provided in /on_search`; + } + }); + } + }); + } catch (error) { + console.log(error); + } return selectObj; }; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/constants.js b/utilities/logistics-b2b/log-verification-utility/utils/constants.js index 56c887f..3ff9912 100755 --- a/utilities/logistics-b2b/log-verification-utility/utils/constants.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/constants.js @@ -171,5 +171,6 @@ module.exports = Object.freeze({ CANCELLATION_TAGS_LIST:["retry_count","rto_id","cancellation_reason_id","sub_reason_id","cancelled_by"], FASHION_ATTRIBUTES : ["brand","colour","size","gender","material"], ELECTRONICS_ATTRIBUTES: ["brand","model"], - TERMS:["bap_terms","bpp_terms"] + TERMS:["buyer_id","bap_terms","bpp_terms"], + B2B_BPP_TERMS:["buyer_id_code","buyer_id_no","max_liability","max_liability_cap","mandatory_arbitration","court_jurisdiction","delay_interest","accept_bpp_terms"] }); diff --git a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js index ef36eae..7c2d4c6 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/logistics/logInit.js @@ -79,7 +79,7 @@ const checkInit = (data, msgIdSet) => { initObj[itemkey] = `Item Id '${item.id}' does not exist in /on_search`; } else { let itemObj = onSearchitemsArr.filter( - (element) => item.id === element.id + (element) => element.id === item.id ); itemObj = itemObj[0]; diff --git a/utilities/logistics-b2b/log-verification-utility/utils/utils.js b/utilities/logistics-b2b/log-verification-utility/utils/utils.js index 04fd841..3c407dc 100755 --- a/utilities/logistics-b2b/log-verification-utility/utils/utils.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/utils.js @@ -365,6 +365,44 @@ const isObjectEqual = (obj1, obj2, parentKey = "") => { return notEqualKeys; }; +function findDifferentAttributes(obj1, obj2) { + const differences = []; + + // Iterate over each key in obj1 + _.forOwn(obj1, (value1, key) => { + const value2 = obj2[key]; + + // Check if the values are not equal + if (!_.isEqual(value1, value2)) { + differences.push(key); + } + }); + + return differences; +} + +function findDifferencesInArrays(array1, array2) { + const differences = []; + + // Check if arrays have the same length + if (array1.length !== array2.length) { + return differences; + } + + // Iterate over each item in the arrays + for (let i = 0; i < array1.length; i++) { + const item1 = array1[i]; + const item2 = array2[i]; + + // Check if the properties are equal using lodash's _.isEqual + if (!_.isEqual(item1, item2)) { + const differingAttributes = findDifferentAttributes(item1, item2); + differences.push({ index: i, attributes: differingAttributes }); + } + } + + return differences; +} module.exports = { uuidCheck, timestampCheck, @@ -390,6 +428,7 @@ module.exports = { taxNotInlcusive, isArrayEqual, countDecimalDigits, + findDifferencesInArrays, grocery_categories_id, fnb_categories_id, }; From bc5c327e712646e9e0c933b94633f132c7f5ec85 Mon Sep 17 00:00:00 2001 From: Abhinav Goyal Date: Tue, 23 Jan 2024 17:08:00 +0530 Subject: [PATCH 8/8] minor fix --- .../log-verification-utility/utils/b2b/b2bConfirm.js | 2 ++ .../log-verification-utility/utils/b2b/b2bInit.js | 2 ++ .../log-verification-utility/utils/b2b/b2bOnSelect.js | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js index f02e68b..2309ecf 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bConfirm.js @@ -18,10 +18,12 @@ const checkConfirm = async (data, msgIdSet) => { const itemDiff = utils.findDifferencesInArrays(items, selectedItems); console.log(itemDiff); itemDiff.forEach((item, i) => { + if(item?.attributes?.length>0){ let itemkey = `item-${i}-DiffErr`; cnfrmObj[ itemkey ] = `In /items, '${item.attributes}' mismatch from /select`; + } }); } catch (error) { console.log(error); diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js index f201555..2bc9084 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bInit.js @@ -16,10 +16,12 @@ const checkInit = (data, msgIdSet) => { const itemDiff = utils.findDifferencesInArrays(items, selectedItems); console.log(itemDiff); itemDiff.forEach((item, i) => { + if(item?.attributes?.length>0){ let itemkey = `item-${i}-DiffErr`; initObj[ itemkey ] = `In /items, '${item.attributes}' mismatch from /select`; + } }); } catch (error) { console.log(error); diff --git a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js index f99599e..49714a9 100644 --- a/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js +++ b/utilities/logistics-b2b/log-verification-utility/utils/b2b/b2bOnSelect.js @@ -30,16 +30,18 @@ const checkOnSelect = async (data, msgIdSet) => { const itemDiff = utils.findDifferencesInArrays(items, selectedItems); console.log(itemDiff); itemDiff.forEach((item, i) => { + if(item?.attributes?.length>0){ let itemkey = `item-${i}-DiffErr`; onSelectObj[ itemkey ] = `In /items, '${item.attributes}' mismatch from /select`; + } }); } catch (error) { console.log(error); } - + try { console.log(`Checking quote object in /on_select api`); quote?.breakup.forEach((breakup, i) => {