Skip to content

Commit

Permalink
chore: test cases contain workspaceId for feature-flag testing
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayteki95 committed Dec 10, 2024
1 parent 35bec9b commit 35a6c4b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
15 changes: 10 additions & 5 deletions src/cdk/v2/destinations/webhook/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ bindings:
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- name: getPropertyParams
- path: ../../../../v0/destinations/webhook/utils
- name: getFormattedPayload
- path: ../../../../v0/destinations/webhook/utils
- name: isFeatureEnabled
- path: ../../../../v0/destinations/webhook/utils
exportAll: true
- name: getHashFromArray
path: ../../../../v0/util
- name: getIntegrationsObj
Expand Down Expand Up @@ -34,7 +38,6 @@ steps:
...configHeaders,
...messageHeader
}
- name: deduceEndPoint
template: |
let integrationsObjects = $.getIntegrationsObj(.message, "webhook");
Expand All @@ -61,8 +64,9 @@ steps:
payload.context.ip = ip;
)
$.context.payload = $.removeUndefinedAndNullValues(payload)
- name: buildResponseForProcessTransformationWithBodyFormatting
condition: await $.isFormattedBodyFeatureEnabled(.metadata.workspaceId) === true
condition: await $.isFeatureEnabled(.metadata.workspaceId, 'dest_transformer_webhook_form_support')
template: |
const finalPayload = {
body: {
Expand All @@ -81,12 +85,13 @@ steps:
files: {},
};
const formattedPayload = $.getFormatedPayload($.context.finalHeaders, $.context.payload);
const formattedPayload = $.getFormattedPayload($.context.finalHeaders, $.context.payload);
finalPayload.body[formattedPayload.contentTypeSimplified] = formattedPayload.payload || {};
$.context.payload = finalPayload;
$.context.payload
- name: buildResponseForProcessTransformationWithDefaultBodyFormat
condition: await $.isFormattedBodyFeatureEnabled(.metadata.workspaceId) !== true
condition: await $.isFeatureEnabled(.metadata.workspaceId, 'dest_transformer_webhook_form_support') !== true
template: |
$.context.payload.({
"body": {
Expand Down
24 changes: 9 additions & 15 deletions src/v0/destinations/webhook/utils.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
const { isFeatureEnabled } = require('feature-flag-sdk');
const { getXMLPayload, getFORMPayload } = require('../../../cdk/v2/destinations/http/utils');
const { EventType } = require('../../../constants');
const { getFieldValueFromMessage, flattenJson } = require('../../util');
const { isFeatureEnabled, setDefaultTraits } = require('feature-flag-sdk')


const JSON = 'JSON',
XML = 'XML',
FORM = 'FORM';
const JSON = 'JSON';
const XML = 'XML';
const FORM = 'FORM';

const ContentTypeConstants = {
'application/json': JSON,
'application/xml': XML,
'text/xml': XML,
'application/x-www-form-urlencoded': FORM
}

const isFormattedBodyFeatureEnabled = async (workspaceId) => {
return await isFeatureEnabled(workspaceId, 'dest_transformer_webhook_form_support');
}
'application/x-www-form-urlencoded': FORM,
};

const getFormatedPayload = (headers, payload) => {
const getFormattedPayload = (headers, payload) => {
const normalizedHeaders = Object.keys(headers).reduce((acc, key) => {
acc[key.toLowerCase()] = headers[key];
return acc;
Expand All @@ -46,7 +41,6 @@ const getPropertyParams = (message) => {

module.exports = {
getPropertyParams,
getFormatedPayload,
isFormattedBodyFeatureEnabled,
ContentTypeConstants
getFormattedPayload,
isFeatureEnabled,
};
8 changes: 5 additions & 3 deletions test/integrations/destinations/webhook/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ export const data = [
},
{
from: 'content-type',
to: 'application/x-www-form-urlencoded'
}
to: 'application/x-www-form-urlencoded',
},
],
},
DestinationDefinition: {
Expand Down Expand Up @@ -3479,6 +3479,7 @@ export const data = [
},
metadata: {
destinationId: '1234',
workspaceId: 'wspId',
},
},
],
Expand All @@ -3491,6 +3492,7 @@ export const data = [
{
metadata: {
destinationId: '1234',
workspaceId: 'wspId',
},
output: {
body: {
Expand Down Expand Up @@ -3539,5 +3541,5 @@ export const data = [
],
},
},
}
},
];
20 changes: 10 additions & 10 deletions test/integrations/destinations/webhook/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const data = [
versionSessionCount: 2,
},
},
metadata: { jobId: 2, userId: 'u1' },
metadata: { jobId: 2, userId: 'u1', workspaceId: 'wkspid' },
destination: {
Config: {
webhookUrl: 'http://6b0e6a60.ngrok.io',
Expand Down Expand Up @@ -183,7 +183,7 @@ export const data = [
versionSessionCount: 2,
},
},
metadata: { jobId: 3, userId: 'u1' },
metadata: { jobId: 3, userId: 'u1', workspaceId: 'wkspid' },
destination: {
Config: { webhookUrl: 'https://6b0e6a60.ngrok.io/n' },
DestinationDefinition: { Config: { cdkV2Enabled: true } },
Expand Down Expand Up @@ -296,7 +296,7 @@ export const data = [
type: 'REST',
method: 'POST',
},
metadata: [{ jobId: 2, userId: 'u1' }],
metadata: [{ jobId: 2, userId: 'u1', workspaceId: 'wkspid' }],
batched: false,
statusCode: 200,
destination: {
Expand Down Expand Up @@ -406,7 +406,7 @@ export const data = [
type: 'REST',
method: 'POST',
},
metadata: [{ jobId: 3, userId: 'u1' }],
metadata: [{ jobId: 3, userId: 'u1', workspaceId: 'wkspid' }],
batched: false,
statusCode: 200,
destination: {
Expand Down Expand Up @@ -505,7 +505,7 @@ export const data = [
type: 'identify',
userId: 'sample_user_id',
},
metadata: { jobId: 2, userId: 'u1' },
metadata: { jobId: 2, userId: 'u1', workspaceId: 'wkspid' },
destination: {
Config: {
webhookUrl: 'http://6b0e6a60.ngrok.io',
Expand Down Expand Up @@ -558,7 +558,7 @@ export const data = [
type: 'identify',
userId: 'sample_user_id',
},
metadata: { jobId: 3, userId: 'u1' },
metadata: { jobId: 3, userId: 'u1', workspaceId: 'wkspid' },
destination: {
Config: { webhookUrl: 'https://6b0e6a60.ngrok.io/n' },
DestinationDefinition: { Config: { cdkV2Enabled: true } },
Expand All @@ -576,7 +576,7 @@ export const data = [
type: 'identify',
userId: 'sample_user_id',
},
metadata: { jobId: 4, userId: 'u1' },
metadata: { jobId: 4, userId: 'u1', workspaceId: 'wkspid' },
destination: {
Config: { webhookUrl: 'https://6b0e6a60.ngrok.io/n' },
DestinationDefinition: { Config: { cdkV2Enabled: true } },
Expand Down Expand Up @@ -684,7 +684,7 @@ export const data = [
type: 'REST',
method: 'POST',
},
metadata: [{ jobId: 2, userId: 'u1' }],
metadata: [{ jobId: 2, userId: 'u1', workspaceId: 'wkspid' }],
batched: false,
statusCode: 200,
destination: {
Expand Down Expand Up @@ -754,7 +754,7 @@ export const data = [
type: 'REST',
method: 'POST',
},
metadata: [{ jobId: 3, userId: 'u1' }],
metadata: [{ jobId: 3, userId: 'u1', workspaceId: 'wkspid' }],
batched: false,
statusCode: 200,
destination: {
Expand Down Expand Up @@ -791,7 +791,7 @@ export const data = [
type: 'REST',
method: 'POST',
},
metadata: [{ jobId: 4, userId: 'u1' }],
metadata: [{ jobId: 4, userId: 'u1', workspaceId: 'wkspid' }],
batched: false,
statusCode: 200,
destination: {
Expand Down

0 comments on commit 35a6c4b

Please sign in to comment.