Skip to content

Commit

Permalink
fix: do not send 298 event for aborted ones in ut
Browse files Browse the repository at this point in the history
  • Loading branch information
psrikanth88 committed Oct 19, 2023
1 parent 8261ab3 commit d414064
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/services/userTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export default class UserTransformService {

const transformedEventsWithMetadata: ProcessorTransformationResponse[] = [];
destTransformedEvents.forEach((ev) => {
// add messageId to output set
if (ev.metadata?.messageId) {
messageIdsInOutputSet.add(ev.metadata.messageId);
} else if (ev.metadata?.messageIds) {
ev.metadata.messageIds.forEach((id) => messageIdsInOutputSet.add(id));
}
if (ev.error) {
transformedEventsWithMetadata.push({
statusCode: 400,
Expand All @@ -114,12 +120,6 @@ export default class UserTransformService {
} as ProcessorTransformationResponse);
return;
}
// add messageId to output set
if (ev.metadata?.messageId) {
messageIdsInOutputSet.add(ev.metadata.messageId);
} else if (ev.metadata?.messageIds) {
ev.metadata.messageIds.forEach((id) => messageIdsInOutputSet.add(id));
}
transformedEventsWithMetadata.push({
output: ev.transformedEvent,
metadata: isEmpty(ev.metadata) ? commonMetadata : ev.metadata,
Expand Down
62 changes: 62 additions & 0 deletions test/__tests__/data/user_transformation_service_filter_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,67 @@
}
]
}
},
{
"message": {
"channel": "web",
"context": {
"app": {
"build": "1.0.0",
"name": "RudderLabs JavaScript SDK",
"namespace": "com.rudderlabs.javascript",
"version": "1.0.0"
},
"traits": {
"email": "test@rudderstack.com",
"anonymousId": "12345"
},
"library": {
"name": "RudderLabs JavaScript SDK",
"version": "1.0.0"
},
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36",
"locale": "en-US",
"ip": "0.0.0.0",
"os": {
"name": "",
"version": ""
},
"screen": {
"density": 2
}
},
"type": "non-standard",
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
"originalTimestamp": "2019-10-14T11:15:18.300Z",
"anonymousId": "00000000000000000000000000",
"userId": "12345",
"event": "test track event GA3",
"properties": {
"user_actual_role": "system_admin, system_user",
"user_actual_id": 12345
},
"integrations": {
"All": true
},
"sentAt": "2019-10-14T11:15:53.296Z"
},
"metadata": {
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
"sourceId": "s1",
"destinationId": "d1"
},
"destination": {
"ID": 2,
"Config": {
"trackingID": "abcd"
},
"Enabled": true,
"Transformations": [
{
"VersionID": "24"
}
]
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@
"destinationId": "d1"
},
"statusCode": 200
},
{
"error": "Error: non-standard event\n at transformEvent (base transformation:5:56)",
"metadata": {
"destinationId": "d1",
"messageId": "ec5481b6-a926-4d2e-b293-0b3a77c4d3be",
"sourceId": "s1"
},
"statusCode": 400
}
],
"retryStatus": 200
Expand Down
3 changes: 2 additions & 1 deletion test/__tests__/user_transformation_ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const name = 'User Transformations';
const randomID = () => Math.random().toString(36).substring(2, 15);

describe('User Transform Service', () => {
fit(`Filtering ${name} Test`, async () => {
it(`Filtering ${name} Test`, async () => {
const versionId = '24'; // set in input file
const inputData = require(`./data/${integration}_filter_input.json`);
const expectedData = require(`./data/${integration}_filter_output.json`);
Expand All @@ -21,6 +21,7 @@ describe('User Transform Service', () => {
const eventType = event.type;
log(eventType);
log(eventType.match(/track/g));
if(eventType === 'non-standard') throw new Error('non-standard event');
if(eventType && !eventType.match(/track/g)) return;
return event;
}
Expand Down

0 comments on commit d414064

Please sign in to comment.