Skip to content

Commit

Permalink
fix: handle empty userId (movable ink, bloomreach) (#3300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia authored Apr 26, 2024
2 parents 999b83e + 5402b21 commit 038c1aa
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/cdk/v2/destinations/bloomreach/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ steps:
const userId = .message.().(
{{{{$.getGenericPaths("userIdOnly")}}}};
);
$.assert(userId ?? .message.anonymousId, "Either one of userId or anonymousId is required. Aborting");
$.assert(userId || .message.anonymousId, "Either one of userId or anonymousId is required. Aborting");
- name: prepareIdentifyPayload
condition: $.context.messageType === {{$.EventType.IDENTIFY}}
Expand All @@ -64,7 +64,7 @@ steps:
- name: pageEventName
condition: $.context.messageType === {{$.EventType.PAGE}}
template: |
const category = .message.category ?? .message.properties.category;
const category = .message.category || .message.properties.category;
const name = .message.name || .message.properties.name;
const eventNameArray = ["Viewed"];
category ? eventNameArray.push(category);
Expand All @@ -74,7 +74,7 @@ steps:
- name: screenEventName
condition: $.context.messageType === {{$.EventType.SCREEN}}
template: |
const category = .message.category ?? .message.properties.category;
const category = .message.category || .message.properties.category;
const name = .message.name || .message.properties.name;
const eventNameArray = ["Viewed"];
category ? eventNameArray.push(category);
Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/movable_ink/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ steps:
{{{{$.getGenericPaths("email")}}}};
);
$.assert(userId ?? email ?? .message.anonymousId, "Either one of userId or email or anonymousId is required. Aborting");
$.assert(userId || email || .message.anonymousId, "Either one of userId or email or anonymousId is required. Aborting");
$.validateEventPayload(.message);
- name: preparePayload
Expand All @@ -50,7 +50,7 @@ steps:
));
$.context.payload = {
...(.message),
userId: userId ?? email,
userId: userId || email,
timestamp: timestampInUnix,
anonymousId: .message.anonymousId
}
Expand Down
59 changes: 58 additions & 1 deletion test/integrations/destinations/bloomreach/processor/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const page: ProcessorTestData[] = [
{
id: 'bloomreach-page-test-1',
name: destType,
description: 'Page call with category, name',
description: 'Page call with category from properties and root-level name',
scenario: 'Framework+Business',
successCriteria:
'Response should contain event_name = "Viewed {{ category }} {{ name }} Page" and properties and status code should be 200',
Expand Down Expand Up @@ -69,4 +69,61 @@ export const page: ProcessorTestData[] = [
},
},
},
{
id: 'bloomreach-page-test-2',
name: destType,
description: 'Page call with category, name from properties',
scenario: 'Framework+Business',
successCriteria:
'Response should contain event_name = "Viewed {{ category }} {{ name }} Page" and properties and status code should be 200',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
type: 'page',
anonymousId: 'anonId123',
name: '',
properties: { ...properties, name: 'Integration' },
integrations: {
All: true,
},
originalTimestamp: '2024-03-04T15:32:56.409Z',
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: transformResultBuilder({
method: 'POST',
userId: '',
endpoint,
headers,
JSON: {
data: {
customer_ids: { cookie: 'anonId123' },
properties: { ...properties, name: 'Integration' },
timestamp: 1709566376,
event_type: 'Viewed Docs Integration Page',
},
name: 'customers/events',
},
}),
statusCode: 200,
metadata: generateMetadata(1),
},
],
},
},
},
];
78 changes: 76 additions & 2 deletions test/integrations/destinations/bloomreach/processor/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { ProcessorTestData } from '../../../testTypes';
import { generateMetadata } from '../../../testUtils';
import { destType, destination, processorInstrumentationErrorStatTags } from '../common';
import { generateMetadata, transformResultBuilder } from '../../../testUtils';
import {
destType,
destination,
processorInstrumentationErrorStatTags,
traits,
headers,
endpoint,
} from '../common';

export const validation: ProcessorTestData[] = [
{
Expand Down Expand Up @@ -128,4 +135,71 @@ export const validation: ProcessorTestData[] = [
},
},
},
{
id: 'bloomreach-validation-test-4',
name: destType,
description: 'Empty userId and non empty anonymousId',
scenario: 'Framework',
successCriteria: 'Response should contain all the mapping and status code should be 200',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
type: 'identify',
userId: '',
anonymousId: 'anonId123',
traits,
integrations: {
All: true,
},
originalTimestamp: '2024-03-04T15:32:56.409Z',
},
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: transformResultBuilder({
method: 'POST',
userId: '',
endpoint,
headers,
JSON: {
data: {
customer_ids: { registered: '', cookie: 'anonId123' },
properties: {
email: '[email protected]',
first_name: 'John',
last_name: 'Doe',
phone: '1234567890',
city: 'New York',
country: 'USA',
address: {
city: 'New York',
country: 'USA',
pinCode: '123456',
},
},
update_timestamp: 1709566376,
},
name: 'customers',
},
}),
statusCode: 200,
metadata: generateMetadata(1),
},
],
},
},
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const identify: ProcessorTestData[] = [
destination,
message: {
type: 'identify',
userId: '',
anonymousId: 'anonId123',
traits,
integrations: {
Expand Down

0 comments on commit 038c1aa

Please sign in to comment.