From 5f2d0741c7e93c826bc54a9ca8434a01eb4937e1 Mon Sep 17 00:00:00 2001 From: Jayc Date: Thu, 5 Sep 2024 15:43:53 +0530 Subject: [PATCH] chore: adding a new violation type Advance-Rules-Violation --- src/util/eventValidation.js | 23 +++++++++++++++++++++++ test/__tests__/eventValidation.test.js | 6 ++++-- test/__tests__/trackingPlan.test.js | 4 ++-- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/util/eventValidation.js b/src/util/eventValidation.js index 9f3ecd859d..46a494ee5c 100644 --- a/src/util/eventValidation.js +++ b/src/util/eventValidation.js @@ -30,6 +30,7 @@ const violationTypes = { AdditionalProperties: 'Additional-Properties', UnknownViolation: 'Unknown-Violation', UnplannedEvent: 'Unplanned-Event', + AdvanceRulesViolation: 'Advance-Rules-Violation', }; const supportedEventTypes = { @@ -227,6 +228,28 @@ async function validate(event) { }, }; break; + case 'minLength': + case 'maxLength': + case 'pattern': + case 'format': + case 'multipleOf': + case 'minimum': + case 'maximum': + case 'exclusiveMinimum': + case 'exclusiveMaximum': + case 'minItems': + case 'maxItems': + case 'uniqueItems': + case 'enum': + rudderValidationError = { + type: violationTypes.AdvanceRulesViolation, + message: error.message, + meta: { + instancePath: error.instancePath, + schemaPath: error.schemaPath, + }, + }; + break; default: rudderValidationError = { type: violationTypes.UnknownViolation, diff --git a/test/__tests__/eventValidation.test.js b/test/__tests__/eventValidation.test.js index b802b6f886..9f28416457 100644 --- a/test/__tests__/eventValidation.test.js +++ b/test/__tests__/eventValidation.test.js @@ -266,7 +266,8 @@ const validationErrorsTestCases = [ validationErrors: [ { type: "Datatype-Mismatch" }, { type: "Unplanned-Event" }, - { type: "Additional-Properties" } + { type: "Additional-Properties" }, + { type: "Advance-Rules-Violation" } ], output: true }, @@ -283,7 +284,8 @@ const validationErrorsTestCases = [ validationErrors: [ { type: "Datatype-Mismatch" }, { type: "Unplanned-Event" }, - { type: "Additional-Properties" } + { type: "Additional-Properties" }, + { type: "Advance-Rules-Violation" } ], output: true }, diff --git a/test/__tests__/trackingPlan.test.js b/test/__tests__/trackingPlan.test.js index 19606b38b9..1c5db08bd4 100644 --- a/test/__tests__/trackingPlan.test.js +++ b/test/__tests__/trackingPlan.test.js @@ -614,7 +614,7 @@ const eventValidationTestCases = [ trackingPlan, output: [ { - type: "Unknown-Violation", + type: "Advance-Rules-Violation", message: "must be <= 4", meta: { instancePath: "/properties/revenue", @@ -665,7 +665,7 @@ const eventValidationTestCases = [ instancePath: "/properties/dateString", schemaPath: "#/properties/properties/properties/dateString/format", }, - type: "Unknown-Violation", + type: "Advance-Rules-Violation", } ] },