Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add event validation for movable ink destination #3190

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
],
},
},
},
];
Loading