From 35a6c4bc68bcbb671fa046a8c46cd922e1d9fcc9 Mon Sep 17 00:00:00 2001 From: Vinay Teki Date: Tue, 10 Dec 2024 17:56:40 +0530 Subject: [PATCH] chore: test cases contain workspaceId for feature-flag testing --- .../v2/destinations/webhook/procWorkflow.yaml | 15 ++++++++---- src/v0/destinations/webhook/utils.js | 24 +++++++------------ .../destinations/webhook/processor/data.ts | 8 ++++--- .../destinations/webhook/router/data.ts | 20 ++++++++-------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/cdk/v2/destinations/webhook/procWorkflow.yaml b/src/cdk/v2/destinations/webhook/procWorkflow.yaml index cf5f4d71dc..edc3c2b2e6 100644 --- a/src/cdk/v2/destinations/webhook/procWorkflow.yaml +++ b/src/cdk/v2/destinations/webhook/procWorkflow.yaml @@ -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 @@ -34,7 +38,6 @@ steps: ...configHeaders, ...messageHeader } - - name: deduceEndPoint template: | let integrationsObjects = $.getIntegrationsObj(.message, "webhook"); @@ -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: { @@ -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": { diff --git a/src/v0/destinations/webhook/utils.js b/src/v0/destinations/webhook/utils.js index 61220f23fa..08ab765ec5 100644 --- a/src/v0/destinations/webhook/utils.js +++ b/src/v0/destinations/webhook/utils.js @@ -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; @@ -46,7 +41,6 @@ const getPropertyParams = (message) => { module.exports = { getPropertyParams, - getFormatedPayload, - isFormattedBodyFeatureEnabled, - ContentTypeConstants + getFormattedPayload, + isFeatureEnabled, }; diff --git a/test/integrations/destinations/webhook/processor/data.ts b/test/integrations/destinations/webhook/processor/data.ts index e3e7eee18d..c81fc31501 100644 --- a/test/integrations/destinations/webhook/processor/data.ts +++ b/test/integrations/destinations/webhook/processor/data.ts @@ -115,8 +115,8 @@ export const data = [ }, { from: 'content-type', - to: 'application/x-www-form-urlencoded' - } + to: 'application/x-www-form-urlencoded', + }, ], }, DestinationDefinition: { @@ -3479,6 +3479,7 @@ export const data = [ }, metadata: { destinationId: '1234', + workspaceId: 'wspId', }, }, ], @@ -3491,6 +3492,7 @@ export const data = [ { metadata: { destinationId: '1234', + workspaceId: 'wspId', }, output: { body: { @@ -3539,5 +3541,5 @@ export const data = [ ], }, }, - } + }, ]; diff --git a/test/integrations/destinations/webhook/router/data.ts b/test/integrations/destinations/webhook/router/data.ts index 6c738ee8a7..305e78fdbc 100644 --- a/test/integrations/destinations/webhook/router/data.ts +++ b/test/integrations/destinations/webhook/router/data.ts @@ -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', @@ -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 } }, @@ -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: { @@ -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: { @@ -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', @@ -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 } }, @@ -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 } }, @@ -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: { @@ -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: { @@ -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: {