Skip to content

Commit

Permalink
fix: comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
AASHISH MALIK committed Dec 16, 2024
1 parent 3a3793c commit 0a091e3
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/cdk/v2/destinations/http/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down
88 changes: 82 additions & 6 deletions test/integrations/destinations/http/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
Expand Down
97 changes: 96 additions & 1 deletion test/integrations/destinations/http/processor/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const configuration: ProcessorTestData[] = [
'content-type': 'application/json',
},
FORM: {
payload: 'event=Order%20Completed&currency=USD&userId=userId123&properties=',
payload: 'event=Order%20Completed&currency=USD&userId=userId123',
},
}),
statusCode: 200,
Expand All @@ -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&currency=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),
},
],
},
},
},
];

0 comments on commit 0a091e3

Please sign in to comment.