diff --git a/test/__tests__/eventValidation.test.js b/test/__tests__/eventValidation.test.js index e79ff390ee..b802b6f886 100644 --- a/test/__tests__/eventValidation.test.js +++ b/test/__tests__/eventValidation.test.js @@ -508,42 +508,6 @@ const eventValidationTestCases = [ violationType: "None" } }, - { - testCase: "Group is part of new Tracking Plan + additional property violation", - event: { - metadata: { - trackingPlanId: "dummy_tracking_plan_id_new", - trackingPlanVersion: "dummy_version_new", - workspaceId: "dummy_workspace_id", - mergedTpConfig, - sourceTpConfig - }, - message: { - type: "group", - userId: "user12345", - groupId: "group1", - traits: { - company: "Company", - employees: 123 - }, - context: { - traits: { - trait1: "new-val" - }, - ip: "14.5.67.21", - library: { - name: "http" - } - }, - timestamp: "2020-01-21T00:21:34.208Z" - } - }, - trackingPlan: newTrackingPlan, - output: { - dropEvent: true, - violationType: violationTypes.AdditionalProperties - } - }, { testCase: "Identify is not part of Tracking Plan", event: { @@ -1209,23 +1173,23 @@ const eventValidationTestCases = [ }, { testCase: - "Compatibility for Spread sheet plugin + Track is not part of new Tracking Plan and allowUnplannedEvents is set to text TRUE", + "Compatibility for Spread sheet plugin + Track is not part of Tracking Plan and allowUnplannedEvents is set to text FALSE", event: { metadata: { - trackingPlanId: "dummy_tracking_plan_id_new", - trackingPlanVersion: "dummy_version_new", + trackingPlanId: "dummy_tracking_plan_id", + trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - allowUnplannedEvents: "TRUE", + allowUnplannedEvents: "FALSE", ajvOptions: {} }, sourceTpConfig: { track: { - allowUnplannedEvents: "TRUE", + allowUnplannedEvents: "FALSE", ajvOptions: {} }, global: { - allowUnplannedEvents: "FALSE", + allowUnplannedEvents: "TRUE", ajvOptions: {} } } @@ -1247,31 +1211,27 @@ const eventValidationTestCases = [ timestamp: "2020-02-02T00:23:09.544Z" } }, - trackingPlan: newTrackingPlan, + trackingPlan, output: { - dropEvent: false, - violationType: "None" + dropEvent: true, + violationType: violationTypes.UnplannedEvent } }, { testCase: - "Compatibility for Spread sheet plugin + Track is not part of Tracking Plan and allowUnplannedEvents is set to text FALSE", + "Track is part of Tracking Plan + no track config and unplannedProperties is set to drop", event: { metadata: { trackingPlanId: "dummy_tracking_plan_id", trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - allowUnplannedEvents: "FALSE", + unplannedProperties: "drop", ajvOptions: {} }, sourceTpConfig: { - track: { - allowUnplannedEvents: "FALSE", - ajvOptions: {} - }, global: { - allowUnplannedEvents: "TRUE", + unplannedProperties: "drop", ajvOptions: {} } } @@ -1279,13 +1239,14 @@ const eventValidationTestCases = [ message: { type: "track", userId: "user-demo", - event: "New Product clicked", + event: "Product clicked", properties: { name: "Rubik's Cube", revenue: 4.99, prop_integer: 2, prop_float: 2.3, - email: "demo@rudderstack.com" + email: "demo@rudderstack.com", + mobile: "999888777666" }, context: { ip: "14.5.67.21" @@ -1296,24 +1257,24 @@ const eventValidationTestCases = [ trackingPlan, output: { dropEvent: true, - violationType: violationTypes.UnplannedEvent + violationType: violationTypes.AdditionalProperties } }, { testCase: - "Track is part of Tracking Plan + no track config and unplannedProperties is set to drop", + "Track is part of Tracking Plan + no global config and unplannedProperties is set to forward", event: { metadata: { trackingPlanId: "dummy_tracking_plan_id", trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - unplannedProperties: "drop", + unplannedProperties: "forward", ajvOptions: {} }, sourceTpConfig: { - global: { - unplannedProperties: "drop", + track: { + unplannedProperties: "forward", ajvOptions: {} } } @@ -1338,33 +1299,27 @@ const eventValidationTestCases = [ }, trackingPlan, output: { - dropEvent: true, - violationType: violationTypes.AdditionalProperties + dropEvent: false, + violationType: "None" } }, { - testCase: - "Track is part of new Tracking Plan + no track config and unplannedProperties is set to drop", + testCase: "allowUnplannedEvents set to value other than true/false", event: { metadata: { - trackingPlanId: "dummy_tracking_plan_id_new", - trackingPlanVersion: "dummy_version_new", + trackingPlanId: "dummy_tracking_plan_id", + trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - unplannedProperties: "drop", + allowUnplannedEvents: "unknown", ajvOptions: {} }, - sourceTpConfig: { - global: { - unplannedProperties: "drop", - ajvOptions: {} - } - } + sourceTpConfig }, message: { type: "track", userId: "user-demo", - event: "Product clicked new", + event: "Product clicked", properties: { name: "Rubik's Cube", revenue: 4.99, @@ -1379,30 +1334,24 @@ const eventValidationTestCases = [ timestamp: "2020-02-02T00:23:09.544Z" } }, - trackingPlan: newTrackingPlan, + trackingPlan, output: { - dropEvent: true, - violationType: violationTypes.AdditionalProperties + dropEvent: false, + violationType: "None" } }, { - testCase: - "Track is part of Tracking Plan + no global config and unplannedProperties is set to forward", + testCase: "unplannedProperties set to value other than forward/drop", event: { metadata: { trackingPlanId: "dummy_tracking_plan_id", trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - unplannedProperties: "forward", + unplannedProperties: "unknown", ajvOptions: {} }, - sourceTpConfig: { - track: { - unplannedProperties: "forward", - ajvOptions: {} - } - } + sourceTpConfig }, message: { type: "track", @@ -1429,14 +1378,14 @@ const eventValidationTestCases = [ } }, { - testCase: "allowUnplannedEvents set to value other than true/false", + testCase: "anyOtherViolation set to value other than forward/drop", event: { metadata: { trackingPlanId: "dummy_tracking_plan_id", trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", mergedTpConfig: { - allowUnplannedEvents: "unknown", + anyOtherViolation: "unknown", ajvOptions: {} }, sourceTpConfig @@ -1466,14 +1415,16 @@ const eventValidationTestCases = [ } }, { - testCase: "unplannedProperties set to value other than forward/drop", + testCase: "sendViolatedEventsTo set to value other than procerrors", event: { metadata: { trackingPlanId: "dummy_tracking_plan_id", trackingPlanVersion: "dummy_version", workspaceId: "dummy_workspace_id", + destinationId: "dummy_destination_id", + destinationType: "dummy_destination_type", mergedTpConfig: { - unplannedProperties: "unknown", + sendViolatedEventsTo: "unknown", ajvOptions: {} }, sourceTpConfig @@ -1501,31 +1452,79 @@ const eventValidationTestCases = [ dropEvent: false, violationType: "None" } + } +]; + +const eventValidationWithNewPlanTestCases = [ + { + testCase: "Group is part of new Tracking Plan + additional property violation", + event: { + metadata: { + trackingPlanId: "dummy_tracking_plan_id_new", + trackingPlanVersion: "dummy_version_new", + workspaceId: "dummy_workspace_id", + mergedTpConfig, + sourceTpConfig + }, + message: { + type: "group", + userId: "user12345", + groupId: "group1", + traits: { + company: "Company", + employees: 123 + }, + context: { + traits: { + trait1: "new-val" + }, + ip: "14.5.67.21", + library: { + name: "http" + } + }, + timestamp: "2020-01-21T00:21:34.208Z" + } + }, + trackingPlan: newTrackingPlan, + output: { + dropEvent: true, + violationType: violationTypes.AdditionalProperties + } }, { - testCase: "anyOtherViolation set to value other than forward/drop", + testCase: + "Compatibility for Spread sheet plugin + Track is not part of new Tracking Plan and allowUnplannedEvents is set to text TRUE", event: { metadata: { - trackingPlanId: "dummy_tracking_plan_id", - trackingPlanVersion: "dummy_version", + trackingPlanId: "dummy_tracking_plan_id_new", + trackingPlanVersion: "dummy_version_new", workspaceId: "dummy_workspace_id", mergedTpConfig: { - anyOtherViolation: "unknown", + allowUnplannedEvents: "TRUE", ajvOptions: {} }, - sourceTpConfig + sourceTpConfig: { + track: { + allowUnplannedEvents: "TRUE", + ajvOptions: {} + }, + global: { + allowUnplannedEvents: "FALSE", + ajvOptions: {} + } + } }, message: { type: "track", userId: "user-demo", - event: "Product clicked", + event: "New Product clicked", properties: { name: "Rubik's Cube", revenue: 4.99, prop_integer: 2, prop_float: 2.3, - email: "demo@rudderstack.com", - mobile: "999888777666" + email: "demo@rudderstack.com" }, context: { ip: "14.5.67.21" @@ -1533,31 +1532,35 @@ const eventValidationTestCases = [ timestamp: "2020-02-02T00:23:09.544Z" } }, - trackingPlan, + trackingPlan: newTrackingPlan, output: { dropEvent: false, violationType: "None" } }, { - testCase: "sendViolatedEventsTo set to value other than procerrors", + testCase: + "Track is part of new Tracking Plan + no track config and unplannedProperties is set to drop", event: { metadata: { - trackingPlanId: "dummy_tracking_plan_id", - trackingPlanVersion: "dummy_version", + trackingPlanId: "dummy_tracking_plan_id_new", + trackingPlanVersion: "dummy_version_new", workspaceId: "dummy_workspace_id", - destinationId: "dummy_destination_id", - destinationType: "dummy_destination_type", mergedTpConfig: { - sendViolatedEventsTo: "unknown", + unplannedProperties: "drop", ajvOptions: {} }, - sourceTpConfig + sourceTpConfig: { + global: { + unplannedProperties: "drop", + ajvOptions: {} + } + } }, message: { type: "track", userId: "user-demo", - event: "Product clicked", + event: "Product clicked new", properties: { name: "Rubik's Cube", revenue: 4.99, @@ -1572,12 +1575,12 @@ const eventValidationTestCases = [ timestamp: "2020-02-02T00:23:09.544Z" } }, - trackingPlan, + trackingPlan: newTrackingPlan, output: { - dropEvent: false, - violationType: "None" + dropEvent: true, + violationType: violationTypes.AdditionalProperties } - } + }, ]; describe("Supported Event types testing", () => { @@ -1605,6 +1608,22 @@ describe("Handle validation", () => { }); }); +describe("Handle validation with new tracking plan payload", () => { + eventValidationWithNewPlanTestCases.forEach(testCase => { + it(`should return dropEvent: ${testCase.output.dropEvent}, violationType: ${testCase.output.violationType}`, async () => { + fetch.mockResolvedValue({ + json: jest.fn().mockResolvedValue(testCase.trackingPlan), + status: 200 + }); + const { dropEvent, violationType } = await handleValidation( + testCase.event + ); + expect(dropEvent).toEqual(testCase.output.dropEvent); + expect(violationType).toEqual(testCase.output.violationType); + }); + }); +}); + describe("HandleValidationErrors", () => { validationErrorsTestCases.forEach(testCase => { it(`should return dropEvent ${testCase.output} for ${testCase.test}`, () => {