From 0a091e364e6a4bd3d1dcfabbfb2ada7a8f9a9ba6 Mon Sep 17 00:00:00 2001 From: AASHISH MALIK <=> Date: Mon, 16 Dec 2024 15:07:32 +0530 Subject: [PATCH] fix: comments addressed --- .../v2/destinations/http/procWorkflow.yaml | 9 +- test/integrations/destinations/http/common.ts | 88 +++++++++++++++-- .../http/processor/configuration.ts | 97 ++++++++++++++++++- 3 files changed, 184 insertions(+), 10 deletions(-) diff --git a/src/cdk/v2/destinations/http/procWorkflow.yaml b/src/cdk/v2/destinations/http/procWorkflow.yaml index ddf1ab78c6..76f879adb7 100644 --- a/src/cdk/v2/destinations/http/procWorkflow.yaml +++ b/src/cdk/v2/destinations/http/procWorkflow.yaml @@ -36,10 +36,13 @@ steps: template: | const configAuthHeaders = $.getAuthHeaders(.destination.Config); const additionalConfigHeaders = $.getCustomMappings(.message, .destination.Config.headers); + const contentTypeHeader = $.context.format === "FORM-URLENCODED" ? { 'Content-Type': 'application/x-www-form-urlencoded' } : {}; + $.context.headers = { ...configAuthHeaders, - ...additionalConfigHeaders - } + ...additionalConfigHeaders, + ...contentTypeHeader + }; - name: prepareParams template: | @@ -54,7 +57,7 @@ steps: const payload = $.getCustomMappings(.message, .destination.Config.propertiesMapping); $.context.payload = $.removeUndefinedAndNullValues($.excludeMappedFields(payload, .destination.Config.propertiesMapping)) $.context.format === "XML" && !$.isEmptyObject($.context.payload) ? $.context.payload = {payload: $.getXMLPayload($.context.payload)}; - $.context.format === "FORM" && !$.isEmptyObject($.context.payload) ? $.context.payload = {payload: $.getFORMPayload($.context.payload)}; + ($.context.format === "FORM" || $.context.format === "FORM-URLENCODED") && !$.isEmptyObject($.context.payload) ? $.context.payload = {payload: $.getFORMPayload($.context.payload)}; - name: buildResponseForProcessTransformation template: | diff --git a/test/integrations/destinations/http/common.ts b/test/integrations/destinations/http/common.ts index 563464dfb2..f4b830133a 100644 --- a/test/integrations/destinations/http/common.ts +++ b/test/integrations/destinations/http/common.ts @@ -312,17 +312,93 @@ const destinations: Destination[] = [ from: '$.userId', to: '$.userId', }, + ], + }, + DestinationDefinition: { + DisplayName: displayName, + ID: '123', + Name: destTypeInUpperCase, + Config: { cdkV2Enabled: true }, + }, + Enabled: true, + ID: '123', + Name: destTypeInUpperCase, + Transformations: [], + WorkspaceID: 'test-workspace-id', + }, + { + Config: { + apiUrl: 'http://abc.com/events', + auth: 'bearerTokenAuth', + bearerToken: 'test-token', + method: 'POST', + format: 'FORM-URLENCODED', + headers: [ { - from: '$.properties.products[*].product_id', - to: '$.properties.items[*].item_id', + to: '$.h1', + from: "'val1'", }, { - from: '$.properties.products[*].name', - to: '$.properties.items[*].name', + to: '$.h2', + from: '$.key1', }, + ], + propertiesMapping: [ { - from: '$.properties.products[*].price', - to: '$.properties.items[*].price', + from: '$.event', + to: '$.event', + }, + { + from: '$.properties.currency', + to: '$.currency', + }, + { + from: '$.userId', + to: '$.userId', + }, + ], + }, + DestinationDefinition: { + DisplayName: displayName, + ID: '123', + Name: destTypeInUpperCase, + Config: { cdkV2Enabled: true }, + }, + Enabled: true, + ID: '123', + Name: destTypeInUpperCase, + Transformations: [], + WorkspaceID: 'test-workspace-id', + }, + { + Config: { + apiUrl: 'http://abc.com/events', + auth: 'bearerTokenAuth', + bearerToken: 'test-token', + method: 'POST', + format: 'FORM-URLENCODED', + headers: [ + { + to: '$.h1', + from: "'val1'", + }, + { + to: '$.h2', + from: '$.key1', + }, + ], + propertiesMapping: [ + { + from: '$.event', + to: '$.event', + }, + { + from: '$.properties.currency', + to: '$.currency', + }, + { + from: '$.userId', + to: '$.userId', }, ], }, diff --git a/test/integrations/destinations/http/processor/configuration.ts b/test/integrations/destinations/http/processor/configuration.ts index e6a61c9bf2..56cbf14422 100644 --- a/test/integrations/destinations/http/processor/configuration.ts +++ b/test/integrations/destinations/http/processor/configuration.ts @@ -245,7 +245,7 @@ export const configuration: ProcessorTestData[] = [ 'content-type': 'application/json', }, FORM: { - payload: 'event=Order%20Completed¤cy=USD&userId=userId123&properties=', + payload: 'event=Order%20Completed¤cy=USD&userId=userId123', }, }), statusCode: 200, @@ -255,4 +255,99 @@ export const configuration: ProcessorTestData[] = [ }, }, }, + { + id: 'http-configuration-test-5', + name: destType, + description: 'Track call with bearer token, form url encoded format', + scenario: 'Business', + successCriteria: + 'Response should be in form format with post method, headers and properties mapping', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: destinations[8], + message: { + type: 'track', + userId: 'userId123', + event: 'Order Completed', + properties, + }, + metadata: generateMetadata(1), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + userId: '', + endpoint: destinations[7].Config.apiUrl, + headers: { + Authorization: 'Bearer test-token', + h1: 'val1', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + FORM: { + payload: 'event=Order%20Completed¤cy=USD&userId=userId123', + }, + }), + statusCode: 200, + metadata: generateMetadata(1), + }, + ], + }, + }, + }, + { + id: 'http-configuration-test-6', + name: destType, + description: 'empty body', + scenario: 'Business', + successCriteria: + 'Response should be in form format with post method, headers and properties mapping', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: destinations[9], + message: {}, + metadata: generateMetadata(1), + }, + ], + }, + }, + output: { + response: { + status: 200, + body: [ + { + output: transformResultBuilder({ + method: 'POST', + userId: '', + endpoint: destinations[9].Config.apiUrl, + headers: { + Authorization: 'Bearer test-token', + h1: 'val1', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + FORM: {}, + }), + statusCode: 200, + metadata: generateMetadata(1), + }, + ], + }, + }, + }, ];