From 5402b219ccdeaafb710c8c2828e983e9864a415f Mon Sep 17 00:00:00 2001 From: Gauravudia Date: Mon, 22 Apr 2024 12:17:47 +0530 Subject: [PATCH] fix: handle empty userId --- .../destinations/bloomreach/procWorkflow.yaml | 6 +- .../movable_ink/procWorkflow.yaml | 4 +- .../destinations/bloomreach/processor/page.ts | 59 +++++++++++++- .../bloomreach/processor/validation.ts | 78 ++++++++++++++++++- .../movable_ink/processor/identify.ts | 1 + 5 files changed, 140 insertions(+), 8 deletions(-) diff --git a/src/cdk/v2/destinations/bloomreach/procWorkflow.yaml b/src/cdk/v2/destinations/bloomreach/procWorkflow.yaml index f092d90382..5a9dcaa18d 100644 --- a/src/cdk/v2/destinations/bloomreach/procWorkflow.yaml +++ b/src/cdk/v2/destinations/bloomreach/procWorkflow.yaml @@ -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}} @@ -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); @@ -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); diff --git a/src/cdk/v2/destinations/movable_ink/procWorkflow.yaml b/src/cdk/v2/destinations/movable_ink/procWorkflow.yaml index 394190049b..fef11124b3 100644 --- a/src/cdk/v2/destinations/movable_ink/procWorkflow.yaml +++ b/src/cdk/v2/destinations/movable_ink/procWorkflow.yaml @@ -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 @@ -50,7 +50,7 @@ steps: )); $.context.payload = { ...(.message), - userId: userId ?? email, + userId: userId || email, timestamp: timestampInUnix, anonymousId: .message.anonymousId } diff --git a/test/integrations/destinations/bloomreach/processor/page.ts b/test/integrations/destinations/bloomreach/processor/page.ts index 0c2d27989d..3081feeb26 100644 --- a/test/integrations/destinations/bloomreach/processor/page.ts +++ b/test/integrations/destinations/bloomreach/processor/page.ts @@ -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', @@ -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), + }, + ], + }, + }, + }, ]; diff --git a/test/integrations/destinations/bloomreach/processor/validation.ts b/test/integrations/destinations/bloomreach/processor/validation.ts index ff959d74c6..1a6199abb0 100644 --- a/test/integrations/destinations/bloomreach/processor/validation.ts +++ b/test/integrations/destinations/bloomreach/processor/validation.ts @@ -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[] = [ { @@ -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: 'test@example.com', + 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), + }, + ], + }, + }, + }, ]; diff --git a/test/integrations/destinations/movable_ink/processor/identify.ts b/test/integrations/destinations/movable_ink/processor/identify.ts index e5bbf5a9a7..0fe806df4a 100644 --- a/test/integrations/destinations/movable_ink/processor/identify.ts +++ b/test/integrations/destinations/movable_ink/processor/identify.ts @@ -20,6 +20,7 @@ export const identify: ProcessorTestData[] = [ destination, message: { type: 'identify', + userId: '', anonymousId: 'anonId123', traits, integrations: {