Skip to content

Commit

Permalink
refactor: rename webhook v2 destination to http
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Sep 9, 2024
1 parent 263d075 commit 97b97a2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ bindings:
path: ../../../../constants
- path: ../../bindings/jsontemplate
exportAll: true
- path: ../../../../v0/destinations/webhook/utils
- name: getHashFromArray
path: ../../../../v0/util
- name: getIntegrationsObj
Expand All @@ -19,7 +18,7 @@ bindings:
steps:
- name: validateInput
template: |
$.assertConfig(.destination.Config.webhookUrl, "Webhook URL required. Aborting");
$.assertConfig(.destination.Config.apiUrl, "API URL is required. Aborting");
$.assertConfig(!(.destination.Config.auth === "basicAuth" && !(.destination.Config.username)), "Username is required for Basic Authentication. Aborting");
$.assertConfig(!(.destination.Config.auth === "bearerTokenAuth" && !(.destination.Config.bearerToken)), "Token is required for Bearer Token Authentication. Aborting");
$.assertConfig(!(.destination.Config.auth === "apiKeyAuth" && !(.destination.Config.apiKeyName)), "API Key Name is required for API Key Authentication. Aborting");
Expand Down Expand Up @@ -48,7 +47,7 @@ steps:
- name: deduceEndPoint
template: |
$.context.endpoint = $.addPathParams(.message, .destination.Config.webhookUrl);
$.context.endpoint = $.addPathParams(.message, .destination.Config.apiUrl);
- name: prepareBody
template: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ const getCustomMappings = (message, mapping) => {
try {
return applyCustomMappings(message, mapping);
} catch (e) {
throw new ConfigurationError(`[Webhook]:: Error in custom mappings: ${e.message}`);
throw new ConfigurationError(`Error in custom mappings: ${e.message}`);

Check warning on line 40 in src/cdk/v2/destinations/http/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/http/utils.js#L40

Added line #L40 was not covered by tests
}
};

const addPathParams = (message, webhookUrl) => {
const addPathParams = (message, apiUrl) => {
try {
return applyJSONStringTemplate(message, `\`${webhookUrl}\``);
return applyJSONStringTemplate(message, `\`${apiUrl}\``);
} catch (e) {
throw new ConfigurationError(`[Webhook]:: Error in url template: ${e.message}`);
throw new ConfigurationError(`Error in api url template: ${e.message}`);

Check warning on line 48 in src/cdk/v2/destinations/http/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/http/utils.js#L48

Added line #L48 was not covered by tests
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Destination } from '../../../../src/types';

const destType = 'webhook_v2';
const destTypeInUpperCase = 'WEBHOOK_V2';
const displayName = 'Webhook V2';
const destType = 'http';
const destTypeInUpperCase = 'HTTP';
const displayName = 'HTTP';
const destinations: Destination[] = [
{
Config: {
webhookUrl: 'http://abc.com/contacts',
apiUrl: 'http://abc.com/contacts',
auth: 'noAuth',
method: 'POST',
format: 'JSON',
Expand Down Expand Up @@ -41,7 +41,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts',
apiUrl: 'http://abc.com/contacts',
auth: 'basicAuth',
username: 'test-user',
password: '',
Expand Down Expand Up @@ -92,7 +92,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
apiUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
auth: 'apiKeyAuth',
apiKeyName: 'x-api-key',
apiKeyValue: 'test-api-key',
Expand All @@ -114,7 +114,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
apiUrl: 'http://abc.com/contacts/{{$.traits.email}}/',
auth: 'apiKeyAuth',
apiKeyName: 'x-api-key',
apiKeyValue: 'test-api-key',
Expand All @@ -136,7 +136,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/events',
apiUrl: 'http://abc.com/events',
auth: 'bearerTokenAuth',
bearerToken: 'test-token',
method: 'POST',
Expand Down Expand Up @@ -196,7 +196,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/events',
apiUrl: 'http://abc.com/events',
auth: 'noAuth',
method: 'POST',
format: 'JSON',
Expand Down Expand Up @@ -249,7 +249,7 @@ const destinations: Destination[] = [
},
{
Config: {
webhookUrl: 'http://abc.com/contacts/{{$.traits.phone}}',
apiUrl: 'http://abc.com/contacts/{{$.traits.phone}}',
auth: 'noAuth',
method: 'POST',
format: 'JSON',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { destType, destinations, properties, traits } from '../common';

export const configuration: ProcessorTestData[] = [
{
id: 'webhook_v2-configuration-test-1',
id: 'http-configuration-test-1',
name: destType,
description: 'Identify call with properties mapping',
scenario: 'Business',
Expand Down Expand Up @@ -36,7 +36,7 @@ export const configuration: ProcessorTestData[] = [
output: transformResultBuilder({
method: 'POST',
userId: '',
endpoint: destinations[0].Config.webhookUrl,
endpoint: destinations[0].Config.apiUrl,
JSON: {
contacts: {
first_name: 'John',
Expand All @@ -55,7 +55,7 @@ export const configuration: ProcessorTestData[] = [
},
},
{
id: 'webhook_v2-configuration-test-2',
id: 'http-configuration-test-2',
name: destType,
description: 'Identify call with api key auth, delete method and path params',
scenario: 'Business',
Expand Down Expand Up @@ -100,7 +100,7 @@ export const configuration: ProcessorTestData[] = [
},
},
{
id: 'webhook_v2-configuration-test-3',
id: 'http-configuration-test-3',
name: destType,
description: 'Track call with basic auth, get method, headers and query params mapping',
scenario: 'Business',
Expand Down Expand Up @@ -132,7 +132,7 @@ export const configuration: ProcessorTestData[] = [
output: transformResultBuilder({
method: 'GET',
userId: '',
endpoint: destinations[1].Config.webhookUrl,
endpoint: destinations[1].Config.apiUrl,
headers: {
Authorization: 'Basic dGVzdC11c2VyOg==',
h1: 'val1',
Expand All @@ -151,7 +151,7 @@ export const configuration: ProcessorTestData[] = [
},
},
{
id: 'webhook_v2-configuration-test-4',
id: 'http-configuration-test-4',
name: destType,
description:
'Track call with bearer token, xml format, post method, additional headers and properties mapping',
Expand Down Expand Up @@ -185,7 +185,7 @@ export const configuration: ProcessorTestData[] = [
output: transformResultBuilder({
method: 'POST',
userId: '',
endpoint: destinations[4].Config.webhookUrl,
endpoint: destinations[4].Config.apiUrl,
headers: {
Authorization: 'Bearer test-token',
h1: 'val1',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { generateMetadata } from '../../../testUtils';
import {
destType,
destinations,
traits,
properties,
RouterInstrumentationErrorStatTags,
} from '../common';
import { destType, destinations, traits, properties } from '../common';

const routerRequest1 = {
input: [
Expand Down Expand Up @@ -164,7 +158,7 @@ const routerRequest4 = {

export const data = [
{
id: 'webhook_v2-router-test-1',
id: 'http-router-test-1',
name: destType,
description: 'Batch multiple GET requests in a single batch with given batch size',
scenario: 'Framework',
Expand Down Expand Up @@ -212,7 +206,7 @@ export const data = [
},
},
{
id: 'webhook_v2-router-test-2',
id: 'http-router-test-2',
name: destType,
description:
'Batch multiple GET requests in multiple batches when number of requests are greater then given batch size',
Expand Down Expand Up @@ -334,7 +328,7 @@ export const data = [
},
},
{
id: 'webhook_v2-router-test-3',
id: 'http-router-test-3',
name: destType,
description: 'Batch multiple POST requests with properties mappings',
scenario: 'Framework',
Expand Down Expand Up @@ -389,9 +383,9 @@ export const data = [
},
},
{
id: 'webhook_v2-router-test-4',
id: 'http-router-test-4',
name: destType,
description: 'Batch multiple requests based on webhook url and headers',
description: 'Batch multiple requests based on api url and headers',
scenario: 'Framework',
successCriteria: 'All events should be transformed successfully and status code should be 200',
feature: 'router',
Expand Down

0 comments on commit 97b97a2

Please sign in to comment.