From 0d6499ee84e189bf12fc79530d0e2349d35b5c22 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 17 Jun 2024 11:31:52 +0530 Subject: [PATCH 1/5] feat: onboard closeCRM source --- src/v1/sources/closeCRM/config.js | 3 + src/v1/sources/closeCRM/transform.js | 52 +++++++++ src/v1/sources/closeCRM/transform.test.js | 134 ++++++++++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 src/v1/sources/closeCRM/config.js create mode 100644 src/v1/sources/closeCRM/transform.js create mode 100644 src/v1/sources/closeCRM/transform.test.js diff --git a/src/v1/sources/closeCRM/config.js b/src/v1/sources/closeCRM/config.js new file mode 100644 index 0000000000..410aff8b40 --- /dev/null +++ b/src/v1/sources/closeCRM/config.js @@ -0,0 +1,3 @@ +const excludedFieldList = ['changed_fields', 'previous_data']; + +module.exports = { excludedFieldList }; diff --git a/src/v1/sources/closeCRM/transform.js b/src/v1/sources/closeCRM/transform.js new file mode 100644 index 0000000000..c510ff0008 --- /dev/null +++ b/src/v1/sources/closeCRM/transform.js @@ -0,0 +1,52 @@ +const { removeUndefinedAndNullValues, generateUUID, formatTimeStamp } = require('../../../v0/util'); +const { excludedFieldList } = require('./config'); +const Message = require('../../../v0/sources/message'); + +function processEvent(inputEvent) { + // eslint-disable-next-line @typescript-eslint/naming-convention + const { event, subscription_id } = inputEvent; + + const message = new Message('CloseCRM'); + + // Set event type track + message.setEventType('track'); + + // Set event name + const eventName = `${event.object_type} ${event.action}`; + message.setEventName(eventName); + + // Set userId + if (event.lead_id) { + message.setProperty('userId', event.lead_id); + } else { + message.setProperty('anonymousId', generateUUID()); + } + + // Set messageId + message.setProperty('messageId', event.id); + + // Set Timestamp + message.setProperty( + 'originalTimestamp', + formatTimeStamp(event.date_updated, 'yyyy-MM-ddTHH:mm:ss.SSSZ'), + ); + + // Set properties + message.setProperty('properties', event); + message.setProperty('properties.subscription_id', subscription_id); + + // Remove excluding fields + excludedFieldList.forEach((field) => { + delete message.properties[field]; + }); + + return message; +} + +function process(inputEvent) { + const { event } = inputEvent; + const response = processEvent(event); + return removeUndefinedAndNullValues(response); +} + +exports.process = process; diff --git a/src/v1/sources/closeCRM/transform.test.js b/src/v1/sources/closeCRM/transform.test.js new file mode 100644 index 0000000000..2dc175d4f2 --- /dev/null +++ b/src/v1/sources/closeCRM/transform.test.js @@ -0,0 +1,134 @@ +const { process } = require('./transform'); + +it(`Transform.js Tests`, () => { + const data = { + input: { + event: { + event: { + date_created: '2019-01-15T12:48:23.395000', + meta: { + request_method: 'PUT', + request_path: '/api/v1/opportunity/object_id/', + }, + id: 'ev_123', + action: 'updated', + date_updated: '2019-01-15T12:48:23.395000', + changed_fields: [ + 'confidence', + 'date_updated', + 'status_id', + 'status_label', + 'status_type', + ], + previous_data: { + status_type: 'active', + confidence: 70, + date_updated: '2019-01-15T12:47:39.873000+00:00', + status_id: 'stat_123', + status_label: 'Active', + }, + organization_id: 'orga_123', + data: { + contact_name: 'Mr. Jones', + user_name: 'Joe Kemp', + value_period: 'one_time', + updated_by_name: 'Joe Kemp', + date_created: '2019-01-15T12:41:24.496000+00:00', + user_id: 'user_123', + updated_by: 'user_123', + value_currency: 'USD', + organization_id: 'orga_123', + status_label: 'Won', + contact_id: 'cont_123', + status_type: 'won', + created_by_name: 'Joe Kemp', + id: 'id_12', + lead_name: 'KLine', + date_lost: null, + note: '', + date_updated: '2019-01-15T12:48:23.392000+00:00', + status_id: 'stat_12', + value: 100000, + created_by: 'user_123', + value_formatted: '$1,000', + date_won: '2019-01-15', + lead_id: 'lead_123', + confidence: 100, + }, + request_id: 'req_123', + object_id: 'object_id', + user_id: 'user_123', + object_type: 'opportunity', + lead_id: 'lead_123', + }, + subscription_id: 'whsub_123', + }, + Config: {}, + }, + output: { + context: { + library: { + name: 'unknown', + version: 'unknown', + }, + integration: { + name: 'CloseCRM', + }, + }, + integrations: { + CloseCRM: false, + }, + type: 'track', + event: 'opportunity updated', + messageId: 'ev_123', + userId: 'lead_123', + originalTimestamp: '2019-01-TuT07:18:23.395+00:00', + properties: { + date_created: '2019-01-15T12:48:23.395000', + meta: { + request_method: 'PUT', + request_path: '/api/v1/opportunity/object_id/', + }, + id: 'ev_123', + action: 'updated', + date_updated: '2019-01-15T12:48:23.395000', + organization_id: 'orga_123', + data: { + contact_name: 'Mr. Jones', + user_name: 'Joe Kemp', + value_period: 'one_time', + updated_by_name: 'Joe Kemp', + date_created: '2019-01-15T12:41:24.496000+00:00', + user_id: 'user_123', + updated_by: 'user_123', + value_currency: 'USD', + organization_id: 'orga_123', + status_label: 'Won', + contact_id: 'cont_123', + status_type: 'won', + created_by_name: 'Joe Kemp', + id: 'id_12', + lead_name: 'KLine', + date_lost: null, + note: '', + date_updated: '2019-01-15T12:48:23.392000+00:00', + status_id: 'stat_12', + value: 100000, + created_by: 'user_123', + value_formatted: '$1,000', + date_won: '2019-01-15', + lead_id: 'lead_123', + confidence: 100, + }, + request_id: 'req_123', + object_id: 'object_id', + user_id: 'user_123', + object_type: 'opportunity', + lead_id: 'lead_123', + subscription_id: 'whsub_123', + }, + }, + }; + const output = process(data.input); + expect(output).toEqual(data.output); +}); From a9eabe6b94ab6d633ce2b01c9c2c8a72ab422835 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 19 Jun 2024 09:26:49 +0530 Subject: [PATCH 2/5] fix: fixed timestamp issue --- src/v1/sources/{closeCRM => close_crm}/config.js | 0 src/v1/sources/{closeCRM => close_crm}/transform.js | 7 +++---- src/v1/sources/{closeCRM => close_crm}/transform.test.js | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) rename src/v1/sources/{closeCRM => close_crm}/config.js (100%) rename src/v1/sources/{closeCRM => close_crm}/transform.js (87%) rename src/v1/sources/{closeCRM => close_crm}/transform.test.js (98%) diff --git a/src/v1/sources/closeCRM/config.js b/src/v1/sources/close_crm/config.js similarity index 100% rename from src/v1/sources/closeCRM/config.js rename to src/v1/sources/close_crm/config.js diff --git a/src/v1/sources/closeCRM/transform.js b/src/v1/sources/close_crm/transform.js similarity index 87% rename from src/v1/sources/closeCRM/transform.js rename to src/v1/sources/close_crm/transform.js index c510ff0008..b2831a1f34 100644 --- a/src/v1/sources/closeCRM/transform.js +++ b/src/v1/sources/close_crm/transform.js @@ -1,3 +1,4 @@ +const moment = require('moment'); const { removeUndefinedAndNullValues, generateUUID, formatTimeStamp } = require('../../../v0/util'); const { excludedFieldList } = require('./config'); const Message = require('../../../v0/sources/message'); @@ -26,10 +27,8 @@ function processEvent(inputEvent) { message.setProperty('messageId', event.id); // Set Timestamp - message.setProperty( - 'originalTimestamp', - formatTimeStamp(event.date_updated, 'yyyy-MM-ddTHH:mm:ss.SSSZ'), - ); + const timestamp = moment.utc(event.date_updated); + message.setProperty('originalTimestamp', formatTimeStamp(timestamp, 'yyyy-MM-ddTHH:mm:ss.SSSZ')); // Set properties message.setProperty('properties', event); diff --git a/src/v1/sources/closeCRM/transform.test.js b/src/v1/sources/close_crm/transform.test.js similarity index 98% rename from src/v1/sources/closeCRM/transform.test.js rename to src/v1/sources/close_crm/transform.test.js index 2dc175d4f2..323fe0d012 100644 --- a/src/v1/sources/closeCRM/transform.test.js +++ b/src/v1/sources/close_crm/transform.test.js @@ -82,7 +82,7 @@ it(`Transform.js Tests`, () => { event: 'opportunity updated', messageId: 'ev_123', userId: 'lead_123', - originalTimestamp: '2019-01-TuT07:18:23.395+00:00', + originalTimestamp: '2019-01-TuT12:48:23.395+00:00', properties: { date_created: '2019-01-15T12:48:23.395000', meta: { From 7b15df7fe96cb407d3ee2489e0438b268208f830 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 19 Jun 2024 13:54:50 +0530 Subject: [PATCH 3/5] fix: fixed minor issues --- src/v1/sources/close_crm/transform.js | 2 +- src/v1/sources/close_crm/transform.test.js | 259 ++++++++++++++------- 2 files changed, 179 insertions(+), 82 deletions(-) diff --git a/src/v1/sources/close_crm/transform.js b/src/v1/sources/close_crm/transform.js index b2831a1f34..59b6189633 100644 --- a/src/v1/sources/close_crm/transform.js +++ b/src/v1/sources/close_crm/transform.js @@ -31,7 +31,7 @@ function processEvent(inputEvent) { message.setProperty('originalTimestamp', formatTimeStamp(timestamp, 'yyyy-MM-ddTHH:mm:ss.SSSZ')); // Set properties - message.setProperty('properties', event); + message.setProperty('properties', removeUndefinedAndNullValues(event)); message.setProperty('properties.subscription_id', subscription_id); // Remove excluding fields diff --git a/src/v1/sources/close_crm/transform.test.js b/src/v1/sources/close_crm/transform.test.js index 323fe0d012..f9303a6dc9 100644 --- a/src/v1/sources/close_crm/transform.test.js +++ b/src/v1/sources/close_crm/transform.test.js @@ -1,10 +1,99 @@ const { process } = require('./transform'); -it(`Transform.js Tests`, () => { - const data = { - input: { - event: { +// mock a specific function from the module +jest.mock('../../../v0/util', () => { + const originalModule = jest.requireActual('../../../v0/util'); + return { + ...originalModule, + generateUUID: jest.fn(() => 'generated_uuid'), + }; +}); + +describe('Transform.js Tests', () => { + it(`should transform the event`, () => { + const data = { + input: { event: { + event: { + date_created: '2019-01-15T12:48:23.395000', + meta: { + request_method: 'PUT', + request_path: '/api/v1/opportunity/object_id/', + }, + id: 'ev_123', + action: 'updated', + date_updated: '2019-01-15T12:48:23.395000', + changed_fields: [ + 'confidence', + 'date_updated', + 'status_id', + 'status_label', + 'status_type', + ], + previous_data: { + status_type: 'active', + confidence: 70, + date_updated: '2019-01-15T12:47:39.873000+00:00', + status_id: 'stat_123', + status_label: 'Active', + }, + organization_id: 'orga_123', + data: { + contact_name: 'Mr. Jones', + user_name: 'Joe Kemp', + value_period: 'one_time', + updated_by_name: 'Joe Kemp', + date_created: '2019-01-15T12:41:24.496000+00:00', + user_id: 'user_123', + updated_by: 'user_123', + value_currency: 'USD', + organization_id: 'orga_123', + status_label: 'Won', + contact_id: 'cont_123', + status_type: 'won', + created_by_name: 'Joe Kemp', + id: 'id_12', + lead_name: 'KLine', + date_lost: null, + note: '', + date_updated: '2019-01-15T12:48:23.392000+00:00', + status_id: 'stat_12', + value: 100000, + created_by: 'user_123', + value_formatted: '$1,000', + date_won: '2019-01-15', + lead_id: 'lead_123', + confidence: 100, + }, + request_id: 'req_123', + object_id: 'object_id', + user_id: 'user_123', + object_type: 'opportunity', + lead_id: 'lead_123', + }, + subscription_id: 'whsub_123', + }, + source: {}, + }, + output: { + context: { + library: { + name: 'unknown', + version: 'unknown', + }, + integration: { + name: 'CloseCRM', + }, + }, + integrations: { + CloseCRM: false, + }, + type: 'track', + event: 'opportunity updated', + messageId: 'ev_123', + userId: 'lead_123', + originalTimestamp: '2019-01-TuT12:48:23.395+00:00', + properties: { date_created: '2019-01-15T12:48:23.395000', meta: { request_method: 'PUT', @@ -13,20 +102,6 @@ it(`Transform.js Tests`, () => { id: 'ev_123', action: 'updated', date_updated: '2019-01-15T12:48:23.395000', - changed_fields: [ - 'confidence', - 'date_updated', - 'status_id', - 'status_label', - 'status_type', - ], - previous_data: { - status_type: 'active', - confidence: 70, - date_updated: '2019-01-15T12:47:39.873000+00:00', - status_id: 'stat_123', - status_label: 'Active', - }, organization_id: 'orga_123', data: { contact_name: 'Mr. Jones', @@ -60,75 +135,97 @@ it(`Transform.js Tests`, () => { user_id: 'user_123', object_type: 'opportunity', lead_id: 'lead_123', + subscription_id: 'whsub_123', }, - subscription_id: 'whsub_123', }, - Config: {}, - }, - output: { - context: { - library: { - name: 'unknown', - version: 'unknown', - }, - integration: { - name: 'CloseCRM', + }; + const output = process(data.input); + expect(output).toEqual(data.output); + }); + it(`should transform the event for null lead_id`, () => { + const data = { + input: { + event: { + subscription_id: 'whsub_123', + event: { + id: 'ev_123', + date_created: '2024-06-13T03:53:33.917000', + date_updated: '2024-06-13T03:53:33.917000', + organization_id: 'orga_123', + user_id: 'user_123', + request_id: 'req_123', + api_key_id: null, + oauth_client_id: null, + oauth_scope: null, + object_type: 'group', + object_id: 'group_123', + lead_id: null, + action: 'created', + changed_fields: [], + meta: { + request_path: '/api/v1/graphql/', + request_method: 'POST', + }, + data: { + id: 'group_123', + name: 'Test group', + members: [ + { + user_id: 'user_123', + }, + ], + }, + previous_data: {}, + }, }, + source: {}, }, - integrations: { - CloseCRM: false, - }, - type: 'track', - event: 'opportunity updated', - messageId: 'ev_123', - userId: 'lead_123', - originalTimestamp: '2019-01-TuT12:48:23.395+00:00', - properties: { - date_created: '2019-01-15T12:48:23.395000', - meta: { - request_method: 'PUT', - request_path: '/api/v1/opportunity/object_id/', + output: { + anonymousId: 'generated_uuid', + context: { + integration: { + name: 'CloseCRM', + }, + library: { + name: 'unknown', + version: 'unknown', + }, }, - id: 'ev_123', - action: 'updated', - date_updated: '2019-01-15T12:48:23.395000', - organization_id: 'orga_123', - data: { - contact_name: 'Mr. Jones', - user_name: 'Joe Kemp', - value_period: 'one_time', - updated_by_name: 'Joe Kemp', - date_created: '2019-01-15T12:41:24.496000+00:00', - user_id: 'user_123', - updated_by: 'user_123', - value_currency: 'USD', + event: 'group created', + integrations: { + CloseCRM: false, + }, + messageId: 'ev_123', + originalTimestamp: '2024-06-ThT03:53:33.917+00:00', + properties: { + action: 'created', + data: { + id: 'group_123', + members: [ + { + user_id: 'user_123', + }, + ], + name: 'Test group', + }, + date_created: '2024-06-13T03:53:33.917000', + date_updated: '2024-06-13T03:53:33.917000', + id: 'ev_123', + meta: { + request_method: 'POST', + request_path: '/api/v1/graphql/', + }, + object_id: 'group_123', + object_type: 'group', organization_id: 'orga_123', - status_label: 'Won', - contact_id: 'cont_123', - status_type: 'won', - created_by_name: 'Joe Kemp', - id: 'id_12', - lead_name: 'KLine', - date_lost: null, - note: '', - date_updated: '2019-01-15T12:48:23.392000+00:00', - status_id: 'stat_12', - value: 100000, - created_by: 'user_123', - value_formatted: '$1,000', - date_won: '2019-01-15', - lead_id: 'lead_123', - confidence: 100, + request_id: 'req_123', + subscription_id: 'whsub_123', + user_id: 'user_123', }, - request_id: 'req_123', - object_id: 'object_id', - user_id: 'user_123', - object_type: 'opportunity', - lead_id: 'lead_123', - subscription_id: 'whsub_123', + type: 'track', }, - }, - }; - const output = process(data.input); - expect(output).toEqual(data.output); + }; + const output = process(data.input); + expect(output).toEqual(data.output); + }); }); From efa64d860c69827776766bd412aded43b7f1cbe5 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Wed, 19 Jun 2024 18:47:35 +0530 Subject: [PATCH 4/5] fix: fixed payload --- src/v1/sources/close_crm/transform.js | 10 ++++++++-- src/v1/sources/close_crm/transform.test.js | 1 - 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/v1/sources/close_crm/transform.js b/src/v1/sources/close_crm/transform.js index 59b6189633..b597285e62 100644 --- a/src/v1/sources/close_crm/transform.js +++ b/src/v1/sources/close_crm/transform.js @@ -1,5 +1,10 @@ const moment = require('moment'); -const { removeUndefinedAndNullValues, generateUUID, formatTimeStamp } = require('../../../v0/util'); +const { + removeUndefinedAndNullValues, + removeUndefinedAndNullRecurse, + generateUUID, + formatTimeStamp, +} = require('../../../v0/util'); const { excludedFieldList } = require('./config'); const Message = require('../../../v0/sources/message'); @@ -31,7 +36,8 @@ function processEvent(inputEvent) { message.setProperty('originalTimestamp', formatTimeStamp(timestamp, 'yyyy-MM-ddTHH:mm:ss.SSSZ')); // Set properties - message.setProperty('properties', removeUndefinedAndNullValues(event)); + removeUndefinedAndNullRecurse(event); + message.setProperty('properties', event); message.setProperty('properties.subscription_id', subscription_id); // Remove excluding fields diff --git a/src/v1/sources/close_crm/transform.test.js b/src/v1/sources/close_crm/transform.test.js index f9303a6dc9..6883ce14ce 100644 --- a/src/v1/sources/close_crm/transform.test.js +++ b/src/v1/sources/close_crm/transform.test.js @@ -119,7 +119,6 @@ describe('Transform.js Tests', () => { created_by_name: 'Joe Kemp', id: 'id_12', lead_name: 'KLine', - date_lost: null, note: '', date_updated: '2019-01-15T12:48:23.392000+00:00', status_id: 'stat_12', From 91782eef9c74b05fb8f7dc28c79e82ac68319410 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Fri, 21 Jun 2024 09:27:15 +0530 Subject: [PATCH 5/5] fix: test case --- src/v1/sources/close_crm/transform.test.js | 230 ------------ test/integrations/sources/close_crm/data.ts | 395 ++++++++++++++++++++ 2 files changed, 395 insertions(+), 230 deletions(-) delete mode 100644 src/v1/sources/close_crm/transform.test.js create mode 100644 test/integrations/sources/close_crm/data.ts diff --git a/src/v1/sources/close_crm/transform.test.js b/src/v1/sources/close_crm/transform.test.js deleted file mode 100644 index 6883ce14ce..0000000000 --- a/src/v1/sources/close_crm/transform.test.js +++ /dev/null @@ -1,230 +0,0 @@ -const { process } = require('./transform'); - -// mock a specific function from the module -jest.mock('../../../v0/util', () => { - const originalModule = jest.requireActual('../../../v0/util'); - return { - ...originalModule, - generateUUID: jest.fn(() => 'generated_uuid'), - }; -}); - -describe('Transform.js Tests', () => { - it(`should transform the event`, () => { - const data = { - input: { - event: { - event: { - date_created: '2019-01-15T12:48:23.395000', - meta: { - request_method: 'PUT', - request_path: '/api/v1/opportunity/object_id/', - }, - id: 'ev_123', - action: 'updated', - date_updated: '2019-01-15T12:48:23.395000', - changed_fields: [ - 'confidence', - 'date_updated', - 'status_id', - 'status_label', - 'status_type', - ], - previous_data: { - status_type: 'active', - confidence: 70, - date_updated: '2019-01-15T12:47:39.873000+00:00', - status_id: 'stat_123', - status_label: 'Active', - }, - organization_id: 'orga_123', - data: { - contact_name: 'Mr. Jones', - user_name: 'Joe Kemp', - value_period: 'one_time', - updated_by_name: 'Joe Kemp', - date_created: '2019-01-15T12:41:24.496000+00:00', - user_id: 'user_123', - updated_by: 'user_123', - value_currency: 'USD', - organization_id: 'orga_123', - status_label: 'Won', - contact_id: 'cont_123', - status_type: 'won', - created_by_name: 'Joe Kemp', - id: 'id_12', - lead_name: 'KLine', - date_lost: null, - note: '', - date_updated: '2019-01-15T12:48:23.392000+00:00', - status_id: 'stat_12', - value: 100000, - created_by: 'user_123', - value_formatted: '$1,000', - date_won: '2019-01-15', - lead_id: 'lead_123', - confidence: 100, - }, - request_id: 'req_123', - object_id: 'object_id', - user_id: 'user_123', - object_type: 'opportunity', - lead_id: 'lead_123', - }, - subscription_id: 'whsub_123', - }, - source: {}, - }, - output: { - context: { - library: { - name: 'unknown', - version: 'unknown', - }, - integration: { - name: 'CloseCRM', - }, - }, - integrations: { - CloseCRM: false, - }, - type: 'track', - event: 'opportunity updated', - messageId: 'ev_123', - userId: 'lead_123', - originalTimestamp: '2019-01-TuT12:48:23.395+00:00', - properties: { - date_created: '2019-01-15T12:48:23.395000', - meta: { - request_method: 'PUT', - request_path: '/api/v1/opportunity/object_id/', - }, - id: 'ev_123', - action: 'updated', - date_updated: '2019-01-15T12:48:23.395000', - organization_id: 'orga_123', - data: { - contact_name: 'Mr. Jones', - user_name: 'Joe Kemp', - value_period: 'one_time', - updated_by_name: 'Joe Kemp', - date_created: '2019-01-15T12:41:24.496000+00:00', - user_id: 'user_123', - updated_by: 'user_123', - value_currency: 'USD', - organization_id: 'orga_123', - status_label: 'Won', - contact_id: 'cont_123', - status_type: 'won', - created_by_name: 'Joe Kemp', - id: 'id_12', - lead_name: 'KLine', - note: '', - date_updated: '2019-01-15T12:48:23.392000+00:00', - status_id: 'stat_12', - value: 100000, - created_by: 'user_123', - value_formatted: '$1,000', - date_won: '2019-01-15', - lead_id: 'lead_123', - confidence: 100, - }, - request_id: 'req_123', - object_id: 'object_id', - user_id: 'user_123', - object_type: 'opportunity', - lead_id: 'lead_123', - subscription_id: 'whsub_123', - }, - }, - }; - const output = process(data.input); - expect(output).toEqual(data.output); - }); - it(`should transform the event for null lead_id`, () => { - const data = { - input: { - event: { - subscription_id: 'whsub_123', - event: { - id: 'ev_123', - date_created: '2024-06-13T03:53:33.917000', - date_updated: '2024-06-13T03:53:33.917000', - organization_id: 'orga_123', - user_id: 'user_123', - request_id: 'req_123', - api_key_id: null, - oauth_client_id: null, - oauth_scope: null, - object_type: 'group', - object_id: 'group_123', - lead_id: null, - action: 'created', - changed_fields: [], - meta: { - request_path: '/api/v1/graphql/', - request_method: 'POST', - }, - data: { - id: 'group_123', - name: 'Test group', - members: [ - { - user_id: 'user_123', - }, - ], - }, - previous_data: {}, - }, - }, - source: {}, - }, - output: { - anonymousId: 'generated_uuid', - context: { - integration: { - name: 'CloseCRM', - }, - library: { - name: 'unknown', - version: 'unknown', - }, - }, - event: 'group created', - integrations: { - CloseCRM: false, - }, - messageId: 'ev_123', - originalTimestamp: '2024-06-ThT03:53:33.917+00:00', - properties: { - action: 'created', - data: { - id: 'group_123', - members: [ - { - user_id: 'user_123', - }, - ], - name: 'Test group', - }, - date_created: '2024-06-13T03:53:33.917000', - date_updated: '2024-06-13T03:53:33.917000', - id: 'ev_123', - meta: { - request_method: 'POST', - request_path: '/api/v1/graphql/', - }, - object_id: 'group_123', - object_type: 'group', - organization_id: 'orga_123', - request_id: 'req_123', - subscription_id: 'whsub_123', - user_id: 'user_123', - }, - type: 'track', - }, - }; - const output = process(data.input); - expect(output).toEqual(data.output); - }); -}); diff --git a/test/integrations/sources/close_crm/data.ts b/test/integrations/sources/close_crm/data.ts new file mode 100644 index 0000000000..08b9d13a1b --- /dev/null +++ b/test/integrations/sources/close_crm/data.ts @@ -0,0 +1,395 @@ +import utils from '../../../../src/v0/util'; + +const defaultMockFns = () => { + jest.spyOn(utils, 'generateUUID').mockReturnValue('97fcd7b2-cc24-47d7-b776-057b7b199513'); +}; + +export const data = [ + { + name: 'close_crm', + description: 'lead update', + module: 'source', + version: 'v1', + input: { + request: { + body: [ + { + event: { + event: { + date_created: '2019-01-15T12:48:23.395000', + meta: { + request_method: 'PUT', + request_path: '/api/v1/opportunity/object_id/', + }, + id: 'ev_123', + action: 'updated', + date_updated: '2019-01-15T12:48:23.395000', + changed_fields: [ + 'confidence', + 'date_updated', + 'status_id', + 'status_label', + 'status_type', + ], + previous_data: { + status_type: 'active', + confidence: 70, + date_updated: '2019-01-15T12:47:39.873000+00:00', + status_id: 'stat_123', + status_label: 'Active', + }, + organization_id: 'orga_123', + data: { + contact_name: 'Mr. Jones', + user_name: 'Joe Kemp', + value_period: 'one_time', + updated_by_name: 'Joe Kemp', + date_created: '2019-01-15T12:41:24.496000+00:00', + user_id: 'user_123', + updated_by: 'user_123', + value_currency: 'USD', + organization_id: 'orga_123', + status_label: 'Won', + contact_id: 'cont_123', + status_type: 'won', + created_by_name: 'Joe Kemp', + id: 'id_12', + lead_name: 'KLine', + date_lost: null, + note: '', + date_updated: '2019-01-15T12:48:23.392000+00:00', + status_id: 'stat_12', + value: 100000, + created_by: 'user_123', + value_formatted: '$1,000', + date_won: '2019-01-15', + lead_id: 'lead_123', + confidence: 100, + }, + request_id: 'req_123', + object_id: 'object_id', + user_id: 'user_123', + object_type: 'opportunity', + lead_id: 'lead_123', + }, + subscription_id: 'whsub_123', + }, + source: {}, + }, + ], + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }, + pathSuffix: '', + }, + output: { + response: { + status: 200, + body: [ + { + output: { + batch: [ + { + context: { + library: { + name: 'unknown', + version: 'unknown', + }, + integration: { + name: 'CloseCRM', + }, + }, + integrations: { + CloseCRM: false, + }, + type: 'track', + event: 'opportunity updated', + messageId: 'ev_123', + userId: 'lead_123', + originalTimestamp: '2019-01-TuT12:48:23.395+00:00', + properties: { + date_created: '2019-01-15T12:48:23.395000', + meta: { + request_method: 'PUT', + request_path: '/api/v1/opportunity/object_id/', + }, + id: 'ev_123', + action: 'updated', + date_updated: '2019-01-15T12:48:23.395000', + organization_id: 'orga_123', + data: { + contact_name: 'Mr. Jones', + user_name: 'Joe Kemp', + value_period: 'one_time', + updated_by_name: 'Joe Kemp', + date_created: '2019-01-15T12:41:24.496000+00:00', + user_id: 'user_123', + updated_by: 'user_123', + value_currency: 'USD', + organization_id: 'orga_123', + status_label: 'Won', + contact_id: 'cont_123', + status_type: 'won', + created_by_name: 'Joe Kemp', + id: 'id_12', + lead_name: 'KLine', + note: '', + date_updated: '2019-01-15T12:48:23.392000+00:00', + status_id: 'stat_12', + value: 100000, + created_by: 'user_123', + value_formatted: '$1,000', + date_won: '2019-01-15', + lead_id: 'lead_123', + confidence: 100, + }, + request_id: 'req_123', + object_id: 'object_id', + user_id: 'user_123', + object_type: 'opportunity', + lead_id: 'lead_123', + subscription_id: 'whsub_123', + }, + }, + ], + }, + }, + ], + }, + }, + mockFns: () => { + defaultMockFns(); + }, + }, + { + name: 'close_crm', + description: 'group creation', + module: 'source', + version: 'v1', + input: { + request: { + body: [ + { + event: { + subscription_id: 'whsub_123', + event: { + id: 'ev_123', + date_created: '2024-06-13T03:53:33.917000', + date_updated: '2024-06-13T03:53:33.917000', + organization_id: 'orga_123', + user_id: 'user_123', + request_id: 'req_123', + api_key_id: null, + oauth_client_id: null, + oauth_scope: null, + object_type: 'group', + object_id: 'group_123', + lead_id: null, + action: 'created', + changed_fields: [], + meta: { + request_path: '/api/v1/graphql/', + request_method: 'POST', + }, + data: { + id: 'group_123', + name: 'Test group', + members: [ + { + user_id: 'user_123', + }, + ], + }, + previous_data: {}, + }, + }, + source: {}, + }, + ], + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }, + pathSuffix: '', + }, + output: { + response: { + status: 200, + body: [ + { + output: { + batch: [ + { + anonymousId: '97fcd7b2-cc24-47d7-b776-057b7b199513', + context: { + integration: { + name: 'CloseCRM', + }, + library: { + name: 'unknown', + version: 'unknown', + }, + }, + event: 'group created', + integrations: { + CloseCRM: false, + }, + messageId: 'ev_123', + originalTimestamp: '2024-06-ThT03:53:33.917+00:00', + properties: { + action: 'created', + data: { + id: 'group_123', + members: [ + { + user_id: 'user_123', + }, + ], + name: 'Test group', + }, + date_created: '2024-06-13T03:53:33.917000', + date_updated: '2024-06-13T03:53:33.917000', + id: 'ev_123', + meta: { + request_method: 'POST', + request_path: '/api/v1/graphql/', + }, + object_id: 'group_123', + object_type: 'group', + organization_id: 'orga_123', + request_id: 'req_123', + subscription_id: 'whsub_123', + user_id: 'user_123', + }, + type: 'track', + }, + ], + }, + }, + ], + }, + }, + mockFns: () => { + defaultMockFns(); + }, + }, + { + name: 'close_crm', + description: 'lead deletion', + module: 'source', + version: 'v1', + input: { + request: { + body: [ + { + event: { + subscription_id: 'whsub_123', + event: { + id: 'ev_123', + date_created: '2024-06-14T05:16:04.138000', + date_updated: '2024-06-14T05:16:04.138000', + organization_id: 'orga_123', + user_id: 'user_123', + request_id: 'req_123', + api_key_id: 'api_123', + oauth_client_id: null, + oauth_scope: null, + object_type: 'lead', + object_id: 'lead_123', + lead_id: 'lead_123', + action: 'deleted', + changed_fields: [], + meta: { + request_path: '/api/v1/lead/lead_123/', + request_method: 'DELETE', + }, + data: {}, + previous_data: { + created_by_name: 'Rudder User', + addresses: [], + description: '', + url: null, + date_created: '2024-06-14T05:13:42.239000+00:00', + status_id: 'stat_123', + contact_ids: ['cont_123'], + id: 'lead_12', + date_updated: '2024-06-14T05:13:42.262000+00:00', + updated_by_name: 'Rudder User', + status_label: 'Potential', + name: 'test name', + display_name: 'test name', + organization_id: 'orga_123', + updated_by: 'user_123', + created_by: 'user_123', + }, + }, + }, + source: {}, + }, + ], + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + }, + pathSuffix: '', + }, + output: { + response: { + status: 200, + body: [ + { + output: { + batch: [ + { + context: { + library: { + name: 'unknown', + version: 'unknown', + }, + integration: { + name: 'CloseCRM', + }, + }, + integrations: { + CloseCRM: false, + }, + type: 'track', + event: 'lead deleted', + userId: 'lead_123', + messageId: 'ev_123', + originalTimestamp: '2024-06-FrT05:16:04.138+00:00', + properties: { + id: 'ev_123', + date_created: '2024-06-14T05:16:04.138000', + date_updated: '2024-06-14T05:16:04.138000', + organization_id: 'orga_123', + user_id: 'user_123', + request_id: 'req_123', + api_key_id: 'api_123', + object_type: 'lead', + object_id: 'lead_123', + lead_id: 'lead_123', + action: 'deleted', + meta: { + request_path: '/api/v1/lead/lead_123/', + request_method: 'DELETE', + }, + data: {}, + subscription_id: 'whsub_123', + }, + }, + ], + }, + }, + ], + }, + }, + mockFns: () => { + defaultMockFns(); + }, + }, +];