Skip to content

Commit

Permalink
Validations added
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanya Madaan authored and Tanya Madaan committed Dec 11, 2023
1 parent a9e5502 commit fe5ed71
Show file tree
Hide file tree
Showing 59 changed files with 1,486 additions and 661 deletions.
21 changes: 2 additions & 19 deletions utilities/logistics-b2b/log-verification-utility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

The tool is a NODE.js based server to check the conformance and compliance of the API logs for [logistics](https://docs.google.com/document/d/10GpEuKZE2g96DFJT3HKq6wIEMhPC-kkMZhXNn2jHHXc/edit?pli=1) and [B2B](https://github.com/ONDC-Official/ONDC-RET-Specifications) based on the examples in the API Contract.

The Log Verification Server is a tool designed to validate log files. It offers an endpoint `/validate/<domain name>` that allows users to send a directory path containing log files for verification. The directory can have single log file or all the log files for the complete flow. In case of single log files, if sent in sequence will validate the complete flow for same transaction id.
The server responds with a log report, indicating any errors found in the log files.
The Log Verification Server is a tool designed to validate log files for the [logistics](https://docs.google.com/document/d/10GpEuKZE2g96DFJT3HKq6wIEMhPC-kkMZhXNn2jHHXc/edit?pli=1) and [B2B](https://github.com/ONDC-Official/ONDC-RET-Specifications) domains. It offers an endpoint that allows users to submit a directory path containing log files for verification. The server then responds with a log report, indicating any errors found in the log files.

### Tech

Expand All @@ -27,11 +26,10 @@ cd log-verification-utility
npm i
```

2. Set up the .env file in root directory with the following configuration:
2. Set up the .env file with the following configuration:

```code
MAPPLS_API_KEY=<api_key_value>
PORT=<port>
```
To get the api_key, refer to this link: https://developer.mappls.com/mapping/reverse-geocoding-api

Expand All @@ -48,26 +46,11 @@ The server will be up and running at `http://localhost:3000`
http://localhost:3000/validate/<domainName>
```

Example endpoint for Logistics

**``
http://localhost:3000/validate/logistics
``**

Example endpoint for B2B

**``
http://localhost:3000/validate/b2b
``**

5. Send a POST request to the endpoint with the following parameters:

```code
logPath: <The path to the directory containing the log files>
```

6. Example using Postman:

```
Url: http://localhost:3000/validate/logistics
Request body json: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,13 @@ module.exports = {
locations: {
type: "array",
const: { $data: "/init/0/message/order/provider/locations" },
errorMessage:"mismatch from /init",
items: {
type: "object",
properties: {
id: {
type: "string",

},
},
required: ["id"],
Expand Down Expand Up @@ -274,7 +276,7 @@ module.exports = {
const: { $data: "/init/0/message/order/billing/phone" },
},
},
additionalProperties: false,

required: ["name", "address", "state", "city", "tax_id", "phone"],
},
fulfillments: {
Expand Down Expand Up @@ -361,7 +363,7 @@ module.exports = {
type: "string",
},
},
required: ["phone", "email"],
required: ["phone"],
},
customer: {
type: "object",
Expand Down Expand Up @@ -499,7 +501,7 @@ module.exports = {
},
"@ondc/org/title_type": {
type: "string",
enum: ["item", "Discount", "Packing charges", "delivery ", "tax", "misc"]
enum: ["item", "discount", "packing", "delivery", "tax", "misc"]
},
price: {
type: "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +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: ${/search/0/context/transaction_id}",
},
message_id: {
type: "string",
Expand All @@ -71,7 +70,7 @@ module.exports = {
errorMessage:
"Message ID should not be equal to transaction_id: ${1/transaction_id}",
},
]
],
},
timestamp: {
type: "string",
Expand All @@ -80,7 +79,8 @@ module.exports = {
ttl: {
type: "string",
const: { $data: "2/message/order/provider/ttl" },
errorMessage:"should match provider ttl - ${2/message/order/provider/ttl}"
errorMessage:
"should match provider ttl - ${2/message/order/provider/ttl}",
},
},
required: [
Expand Down Expand Up @@ -118,15 +118,18 @@ module.exports = {
properties: {
id: {
type: "string",
const: { $data: "/select/0/message/order/provider/locations/0/id"}
const: {
$data:
"/select/0/message/order/provider/locations/0/id",
},
},
},
required: ["id"],
},
},
ttl: {
type: "string",
format: "duration"
format: "duration",
},
},
required: ["id", "locations", "ttl"],
Expand Down Expand Up @@ -182,7 +185,7 @@ module.exports = {
properties: {
code: {
type: "string",
enum:["BUYER_TERMS"]
enum: ["BUYER_TERMS"],
},
},
required: ["code"],
Expand All @@ -197,7 +200,7 @@ module.exports = {
properties: {
code: {
type: "string",
enum:["ITEM_REQ","PACKAGING_REQ"]
enum: ["ITEM_REQ", "PACKAGING_REQ"],
},
},
required: ["code"],
Expand Down Expand Up @@ -254,6 +257,12 @@ module.exports = {
phone: {
type: "string",
},
created_at: {
type: "string",
},
updated_at: {
type: "string",
},
},
additionalProperties: false,
required: ["name", "address", "state", "city", "tax_id", "phone"],
Expand Down Expand Up @@ -282,7 +291,8 @@ module.exports = {
properties: {
gps: {
type: "string",
pattern: "^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$",
pattern:
"^(-?[0-9]{1,3}(?:.[0-9]{6,15})?),( )*?(-?[0-9]{1,3}(?:.[0-9]{6,15})?)$",
errorMessage: "Incorrect gps value",
},
address: {
Expand Down Expand Up @@ -384,7 +394,7 @@ module.exports = {
},
},
required: ["person"],
},
},
tags: {
type: "array",
items: {
Expand All @@ -410,7 +420,10 @@ module.exports = {
properties: {
code: {
type: "string",
enum: ["INCOTERMS", "NAMED_PLACE_OF_DELIVERY"],
enum: [
"INCOTERMS",
"NAMED_PLACE_OF_DELIVERY",
],
},
},
required: ["code"],
Expand Down Expand Up @@ -453,22 +466,20 @@ module.exports = {
},
payments: {
type: "array",
items:
{
type: "object",
properties: {
type: {
type: "string",
enum: [
"PRE-FULFILLMENT",
"ON-FULFILLMENT",
"POST-FULFILLMENT",
],
},
items: {
type: "object",
properties: {
type: {
type: "string",
enum: [
"PRE-FULFILLMENT",
"ON-FULFILLMENT",
"POST-FULFILLMENT",
],
},
required: ["type"],
},

required: ["type"],
},
},
tags: {
type: "array",
Expand Down Expand Up @@ -508,7 +519,7 @@ module.exports = {
},
},
},
additionalProperties:false,
additionalProperties: false,
required: [
"provider",
"items",
Expand All @@ -523,4 +534,4 @@ module.exports = {
},
},
required: ["context", "message"],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
isFutureDated: (data) => {
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)
)
return false;
return true;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
isLengthValid: (data) => {
if (data.name.length + data.building.length + data.locality.length > 190)
return false;
else return true;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
isQuoteMatching: (data) => {
const quotePrice = parseFloat(data?.price?.value);
const breakupArr = data.breakup;
let totalBreakup = 0;
breakupArr.forEach((breakup) => {
totalBreakup += parseFloat(breakup?.price?.value);
});
if (quotePrice != totalBreakup) return false;
else return true;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
isEndTimeGreater: (data) => {
const startTime = parseInt(data.start);
const endTime = parseInt(data.end);
return startTime < endTime;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ module.exports = {
const: { $data: "/init/0/message/order/billing/phone" },
},
},
additionalProperties: false,

required: ["name", "address", "state", "city", "tax_id", "phone"],
},
fulfillments: {
Expand Down Expand Up @@ -421,7 +421,7 @@ module.exports = {
type: "string",
},
},
required: ["phone", "email"],
required: ["phone"],
},
},
required: ["type", "location", "time", "contact"],
Expand Down Expand Up @@ -627,6 +627,9 @@ module.exports = {
type: "string",
},
},
isQuoteMatching: true,
errorMessage:
"price is not matching with the total breakup price",
required: ["price", "breakup", "ttl"],
},
payments: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ module.exports = {
const: { $data: "/init/0/message/order/billing/phone" },
},
},
additionalProperties: false,

required: ["name", "address", "state", "city", "tax_id", "phone"],
},
fulfillments: {
Expand Down Expand Up @@ -473,11 +473,7 @@ module.exports = {
},
"@ondc/org/title_type": {
type: "string",
enum: ["item", "delivery",
"packing",
"tax",
"discount",
"misc"]
enum: ["item", "discount", "packing", "delivery", "tax", "misc"]
},
price: {
type: "object",
Expand Down Expand Up @@ -552,6 +548,9 @@ module.exports = {
type: "string",
},
},
isQuoteMatching: true,
errorMessage:
"price is not matching with the total breakup price",
required: ["price", "breakup", "ttl"],
},
payments: {
Expand Down
Loading

0 comments on commit fe5ed71

Please sign in to comment.