Skip to content

Commit

Permalink
chore: add event validation for movable ink destination (#3190)
Browse files Browse the repository at this point in the history
chore: add validation for movable ink destination
  • Loading branch information
Gauravudia authored and shrouti1507 committed Mar 20, 2024
1 parent b2f4830 commit f3e48c6
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cdk/v2/destinations/movable_ink/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ steps:
);
$.assert(userId ?? email ?? .message.anonymousId, "Either one of userId or email or anonymousId is required. Aborting");
$.validateEventPayload(.message);
- name: preparePayload
description: Prepare payload for identify and track. This payload schema needs to be configured in the Movable Ink dashboard. Movable Ink will discard any additional fields from the input payload.
Expand Down
21 changes: 21 additions & 0 deletions src/cdk/v2/destinations/movable_ink/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');

const validateEventPayload = (message) => {
const { event } = message;
const { properties } = message;
if (event === 'Products Searched' && !properties?.query) {
throw new InstrumentationError("Missing 'query' property in properties. Aborting");
}

if (
(event === 'Product Added' ||
event === 'Product Removed' ||
event === 'Product Viewed' ||
event === 'Category Viewed') &&
!properties?.product_id
) {
throw new InstrumentationError("Missing 'product_id' property in properties. Aborting");
}
};

module.exports = { validateEventPayload };
86 changes: 86 additions & 0 deletions test/integrations/destinations/movable_ink/processor/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,90 @@ export const validation: ProcessorTestData[] = [
},
},
},
{
id: 'MovableInk-validation-test-4',
name: destType,
description: "Products Searched event - Missing 'query' property",
scenario: 'Framework',
successCriteria: 'Instrumentation Error',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
type: 'track',
userId: 'user123',
integrations: {
All: true,
},
event: 'Products Searched',
originalTimestamp: '2024-03-04T15:32:56.409Z',
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error:
"Missing 'query' property in properties. Aborting: Workflow: procWorkflow, Step: validateInput, ChildStep: undefined, OriginalError: Missing 'query' property in properties. Aborting",
metadata: generateMetadata(1),
statTags: processorInstrumentationErrorStatTags,
statusCode: 400,
},
],
},
},
},
{
id: 'MovableInk-validation-test-5',
name: destType,
description: "Products Added event - Missing 'product_id' property",
scenario: 'Framework',
successCriteria: 'Instrumentation Error',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
type: 'track',
userId: 'user123',
integrations: {
All: true,
},
event: 'Product Added',
originalTimestamp: '2024-03-04T15:32:56.409Z',
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error:
"Missing 'product_id' property in properties. Aborting: Workflow: procWorkflow, Step: validateInput, ChildStep: undefined, OriginalError: Missing 'product_id' property in properties. Aborting",
metadata: generateMetadata(1),
statTags: processorInstrumentationErrorStatTags,
statusCode: 400,
},
],
},
},
},
];

0 comments on commit f3e48c6

Please sign in to comment.