From 1bd9372aa7720f2939b4b68e41bc9deaa17c0a83 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 3 Jun 2024 10:44:41 +0530 Subject: [PATCH 1/7] feat: add tags to a company --- src/cdk/v2/destinations/intercom/config.js | 2 + .../destinations/intercom/procWorkflow.yaml | 4 + src/cdk/v2/destinations/intercom/utils.js | 57 ++++++++++++ .../v2/destinations/intercom/utils.test.js | 88 +++++++++++++++++++ 4 files changed, 151 insertions(+) diff --git a/src/cdk/v2/destinations/intercom/config.js b/src/cdk/v2/destinations/intercom/config.js index 518d805d41..6e580150e6 100644 --- a/src/cdk/v2/destinations/intercom/config.js +++ b/src/cdk/v2/destinations/intercom/config.js @@ -4,6 +4,7 @@ const BASE_AU_ENDPOINT = 'https://api.au.intercom.io'; const SEARCH_CONTACT_ENDPOINT = 'contacts/search'; const CREATE_OR_UPDATE_COMPANY_ENDPOINT = 'companies'; +const TAGS = 'tags'; const ReservedAttributes = { v1UserAttributes: [ @@ -78,4 +79,5 @@ module.exports = { SEARCH_CONTACT_ENDPOINT, ReservedCompanyProperties, CREATE_OR_UPDATE_COMPANY_ENDPOINT, + TAGS, }; diff --git a/src/cdk/v2/destinations/intercom/procWorkflow.yaml b/src/cdk/v2/destinations/intercom/procWorkflow.yaml index 0a8842d5e7..3cea208b53 100644 --- a/src/cdk/v2/destinations/intercom/procWorkflow.yaml +++ b/src/cdk/v2/destinations/intercom/procWorkflow.yaml @@ -178,6 +178,7 @@ steps: const contactId = $.outputs.searchContact; const companyId = await $.createOrUpdateCompany($.context.payload, .destination); $.assert(companyId, "Unable to create or update company"); + await $.addOrUpdateTagToCompany(.message, .destination, companyId); $.context.payload = { id: companyId, }; @@ -185,6 +186,9 @@ steps: else: name: whenSearchContactNotFound template: | + const companyId = await $.createOrUpdateCompany($.context.payload, .destination); + $.assert(companyId, "Unable to create or update company"); + await $.addOrUpdateTagToCompany(.message, .destination, companyId); $.context.endpoint = $.getBaseEndpoint(.destination) + "/" + "companies"; - name: prepareFinalPayload template: | diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index ba3063c9f9..fe09523db3 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -27,6 +27,7 @@ const { SEARCH_CONTACT_ENDPOINT, ReservedCompanyProperties, CREATE_OR_UPDATE_COMPANY_ENDPOINT, + TAGS, } = require('./config'); /** @@ -369,6 +370,61 @@ const addMetadataToPayload = (payload) => { return finalPayload; }; +/** + * Add or Update tags to a company + * @param message + * @param destination + * @param id + * @returns + */ +const addOrUpdateTagToCompany = async (message, destination, id) => { + const companyTags = message?.traits?.tags || message?.context?.traits?.tags; + if (!companyTags) return; + const headers = getHeaders(destination); + const baseEndPoint = getBaseEndpoint(destination); + const endpoint = `${baseEndPoint}/${TAGS}`; + const statTags = { + destType: 'intercom', + feature: 'transformation', + endpointPath: '/tags', + requestMethod: 'POST', + module: 'router', + }; + await Promise.all( + companyTags.map(async (tag) => { + const finalPayload = { + name: tag, + companies: [ + { + id, + }, + ], + }; + const response = await httpPOST( + endpoint, + finalPayload, + { + headers, + }, + statTags, + ); + const processedResponse = processAxiosResponse(response); + if (!isHttpStatusSuccess(processedResponse.status)) { + throw new NetworkError( + `Unable to Add or Update the Tag to Company due to : ${JSON.stringify( + processedResponse?.response?.errors, + )}`, + processedResponse?.status, + { + [tags]: getDynamicErrorType(processedResponse?.status), + }, + processedResponse, + ); + } + }), + ); +}; + module.exports = { getName, getHeaders, @@ -382,4 +438,5 @@ module.exports = { filterCustomAttributes, checkIfEmailOrUserIdPresent, separateReservedAndRestMetadata, + addOrUpdateTagToCompany, }; diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index e651b4ea5d..d4e55f8c0c 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -13,6 +13,7 @@ const { filterCustomAttributes, checkIfEmailOrUserIdPresent, separateReservedAndRestMetadata, + addOrUpdateTagToCompany, } = require('./utils'); const { BASE_ENDPOINT, BASE_EU_ENDPOINT, BASE_AU_ENDPOINT } = require('./config'); @@ -763,3 +764,90 @@ describe('attachUserAndCompany utility test', () => { expect(response).toEqual(expectedResponse); }); }); + +describe('addOrUpdateTagToCompany utility test', () => { + it('Should successfully add tags to company', async () => { + const message = { + traits: { + tags: ['tag1', 'tag2'], + }, + }; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; + const id = 'companyId'; + + axios.post + .mockResolvedValueOnce({ + status: 200, + data: { type: 'tag', id: '123', name: 'tag1' }, + }) + .mockResolvedValueOnce({ + status: 200, + data: { type: 'tag', id: '124', name: 'tag2' }, + }); + + axios.post.mockClear(); + await addOrUpdateTagToCompany(message, destination, id); + + expect(axios.post).toHaveBeenCalledTimes(2); + + expect(axios.post).toHaveBeenCalledWith( + `${getBaseEndpoint(destination)}/tags`, + { name: 'tag1', companies: [{ id: 'companyId' }] }, + expect.objectContaining({ + headers: getHeaders(destination), + }), + ); + + expect(axios.post).toHaveBeenCalledWith( + `${getBaseEndpoint(destination)}/tags`, + { name: 'tag2', companies: [{ id: 'companyId' }] }, + expect.objectContaining({ + headers: getHeaders(destination), + }), + ); + }); + + it('Should throw an error in case if axios calls returns an error', async () => { + const message = { + traits: { + tags: ['tag1'], + }, + }; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; + const id = 'companyId'; + + axios.post.mockRejectedValue({ + status: 400, + data: { + type: 'error.list', + request_id: 'request_400', + errors: [ + { + code: 'unauthorized', + message: 'Access Token Invalid', + }, + ], + }, + }); + + try { + axios.post.mockClear(); + await addOrUpdateTagToCompany(message, destination, id); + } catch (error) { + expect(error.message).toEqual( + `Unable to Add or Update the Tag to Company due to : [{"code":"unauthorized","message":"Access Token Invalid"}]`, + ); + } + }); + + it('Should do nothing when no tags are provided', async () => { + const message = { traits: {} }; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; + const id = 'companyId'; + + axios.post.mockClear(); + await addOrUpdateTagToCompany(message, destination, id); + + expect(axios.post).not.toHaveBeenCalled(); + }); +}); From 55ba5fa141eb6346b7d49575f717a34ae6dd4cb9 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 10 Jun 2024 09:36:14 +0530 Subject: [PATCH 2/7] feat: modified group call to attach user and add tags to company --- src/cdk/v2/destinations/intercom/config.js | 4 +- .../destinations/intercom/procWorkflow.yaml | 25 +- .../v2/destinations/intercom/rtWorkflow.yaml | 2 +- src/cdk/v2/destinations/intercom/utils.js | 68 +++- .../v2/destinations/intercom/utils.test.js | 23 +- .../destinations/intercom/network.ts | 316 ++++++++++++++++++ .../destinations/intercom/router/data.ts | 4 +- 7 files changed, 418 insertions(+), 24 deletions(-) diff --git a/src/cdk/v2/destinations/intercom/config.js b/src/cdk/v2/destinations/intercom/config.js index 6e580150e6..c3b806f9f9 100644 --- a/src/cdk/v2/destinations/intercom/config.js +++ b/src/cdk/v2/destinations/intercom/config.js @@ -4,7 +4,7 @@ const BASE_AU_ENDPOINT = 'https://api.au.intercom.io'; const SEARCH_CONTACT_ENDPOINT = 'contacts/search'; const CREATE_OR_UPDATE_COMPANY_ENDPOINT = 'companies'; -const TAGS = 'tags'; +const TAGS_ENDPOINT = 'tags'; const ReservedAttributes = { v1UserAttributes: [ @@ -79,5 +79,5 @@ module.exports = { SEARCH_CONTACT_ENDPOINT, ReservedCompanyProperties, CREATE_OR_UPDATE_COMPANY_ENDPOINT, - TAGS, + TAGS_ENDPOINT, }; diff --git a/src/cdk/v2/destinations/intercom/procWorkflow.yaml b/src/cdk/v2/destinations/intercom/procWorkflow.yaml index 3cea208b53..008b22ace5 100644 --- a/src/cdk/v2/destinations/intercom/procWorkflow.yaml +++ b/src/cdk/v2/destinations/intercom/procWorkflow.yaml @@ -16,6 +16,8 @@ bindings: - name: addExternalIdToTraits path: ../../../../v0/util - path: ../../bindings/jsontemplate + - name: HTTP_STATUS_CODES + path: ../../../../v0/util/constant steps: - name: checkIfProcessed @@ -178,18 +180,21 @@ steps: const contactId = $.outputs.searchContact; const companyId = await $.createOrUpdateCompany($.context.payload, .destination); $.assert(companyId, "Unable to create or update company"); - await $.addOrUpdateTagToCompany(.message, .destination, companyId); $.context.payload = { id: companyId, }; $.context.endpoint = $.getBaseEndpoint(.destination) + "/" + "contacts" + "/" + contactId + "/" + "companies"; + const payload = $.context.payload; + const endpoint = $.context.endpoint; + await $.attachContactToCompany(payload, endpoint, .destination); + await $.addOrUpdateTagsToCompany(.message, .destination, companyId); else: name: whenSearchContactNotFound template: | const companyId = await $.createOrUpdateCompany($.context.payload, .destination); $.assert(companyId, "Unable to create or update company"); - await $.addOrUpdateTagToCompany(.message, .destination, companyId); $.context.endpoint = $.getBaseEndpoint(.destination) + "/" + "companies"; + await $.addOrUpdateTagsToCompany(.message, .destination, companyId); - name: prepareFinalPayload template: | $.context.requestMethod = 'POST'; @@ -212,9 +217,25 @@ steps: response.method = "POST"; response.userId = .message.anonymousId; $.context.response.push(response); + payload = response.body.JSON; + const companyId = await $.createOrUpdateCompany(payload, .destination); + $.assert(companyId, "Unable to create or update company"); const attachUserAndCompanyResponse = $.attachUserAndCompany(.message, .destination.Config); attachUserAndCompanyResponse ? attachUserAndCompanyResponse.userId = .message.anonymousId; attachUserAndCompanyResponse ? $.context.response.push(attachUserAndCompanyResponse); + payload = attachUserAndCompanyResponse.body.JSON; + let endpoint = attachUserAndCompanyResponse.endpoint; + attachUserAndCompanyResponse ? await $.attachContactToCompany(payload, endpoint, .destination); + await $.addOrUpdateTagsToCompany(.message, .destination, companyId); + + - name: statusCode + condition: $.outputs.messageType === {{$.EventType.GROUP}} + template: | + $.HTTP_STATUS_CODES.SUPPRESS_EVENTS + else: + name: successStatusCode + template: | + $.HTTP_STATUS_CODES.OK - name: buildResponseForProcessTransformation description: Build response for multiple transformed event diff --git a/src/cdk/v2/destinations/intercom/rtWorkflow.yaml b/src/cdk/v2/destinations/intercom/rtWorkflow.yaml index edb7267b84..65c3a4976d 100644 --- a/src/cdk/v2/destinations/intercom/rtWorkflow.yaml +++ b/src/cdk/v2/destinations/intercom/rtWorkflow.yaml @@ -21,7 +21,7 @@ steps: "batched": false, "destination": ^[idx].destination, "metadata": ^[idx].metadata[], - "statusCode": 200 + "statusCode": .outputs.statusCode })[] - name: failedEvents template: | diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index fe09523db3..7ada43cf37 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -27,7 +27,7 @@ const { SEARCH_CONTACT_ENDPOINT, ReservedCompanyProperties, CREATE_OR_UPDATE_COMPANY_ENDPOINT, - TAGS, + TAGS_ENDPOINT, } = require('./config'); /** @@ -286,7 +286,8 @@ const searchContact = async (message, destination) => { * @returns */ const createOrUpdateCompany = async (payload, destination) => { - const headers = getHeaders(destination); + const { apiVersion } = destination.Config; + const headers = getHeaders(destination, apiVersion); const finalPayload = JSON.stringify(removeUndefinedAndNullValues(payload)); const baseEndPoint = getBaseEndpoint(destination); const endpoint = `${baseEndPoint}/${CREATE_OR_UPDATE_COMPANY_ENDPOINT}`; @@ -371,18 +372,68 @@ const addMetadataToPayload = (payload) => { }; /** - * Add or Update tags to a company + * Api call to attach user to the company + * Ref doc v1: https://developers.intercom.com/docs/references/1.4/rest-api/users/companies-and-users/ + * Ref doc v2: https://developers.intercom.com/docs/references/2.10/rest-api/api.intercom.io/Contacts/attachContactToACompany/ + * @param {*} payload + * @param {*} endpoint + * @param {*} destination + */ +const attachContactToCompany = async (payload, endpoint, destination) => { + let { apiVersion } = destination.Config; + apiVersion = isDefinedAndNotNull(apiVersion) ? apiVersion : 'v2'; + let endpointPath = '/contact/{id}/companies'; + if (apiVersion === 'v1') { + endpointPath = '/users'; + } + const headers = getHeaders(destination, apiVersion); + const finalPayload = JSON.stringify(removeUndefinedAndNullValues(payload)); + const response = await httpPOST( + endpoint, + finalPayload, + { + headers, + }, + { + destType: 'intercom', + feature: 'transformation', + endpointPath, + requestMethod: 'POST', + module: 'router', + }, + ); + + const processedResponse = processAxiosResponse(response); + if (!isHttpStatusSuccess(processedResponse.status)) { + throw new NetworkError( + `Unable to attach Contact to Company due to : ${JSON.stringify( + processedResponse?.response?.errors, + )}`, + processedResponse?.status, + { + [tags]: getDynamicErrorType(processedResponse?.status), + }, + processedResponse, + ); + } +}; + +/** + * Api calls to add or update tags to the company + * Ref doc v1: https://developers.intercom.com/docs/references/1.4/rest-api/tags/tag-or-untag-users-companies-leads-contacts/ + * Ref doc v2: https://developers.intercom.com/docs/references/2.10/rest-api/api.intercom.io/Tags/createTag/ * @param message * @param destination * @param id * @returns */ -const addOrUpdateTagToCompany = async (message, destination, id) => { - const companyTags = message?.traits?.tags || message?.context?.traits?.tags; +const addOrUpdateTagsToCompany = async (message, destination, id) => { + const companyTags = message?.context?.traits?.tags; if (!companyTags) return; - const headers = getHeaders(destination); + const { apiVersion } = destination.Config; + const headers = getHeaders(destination, apiVersion); const baseEndPoint = getBaseEndpoint(destination); - const endpoint = `${baseEndPoint}/${TAGS}`; + const endpoint = `${baseEndPoint}/${TAGS_ENDPOINT}`; const statTags = { destType: 'intercom', feature: 'transformation', @@ -438,5 +489,6 @@ module.exports = { filterCustomAttributes, checkIfEmailOrUserIdPresent, separateReservedAndRestMetadata, - addOrUpdateTagToCompany, + attachContactToCompany, + addOrUpdateTagsToCompany, }; diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index d4e55f8c0c..cdc01cb1ad 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -13,7 +13,8 @@ const { filterCustomAttributes, checkIfEmailOrUserIdPresent, separateReservedAndRestMetadata, - addOrUpdateTagToCompany, + attachContactToCompany, + addOrUpdateTagsToCompany, } = require('./utils'); const { BASE_ENDPOINT, BASE_EU_ENDPOINT, BASE_AU_ENDPOINT } = require('./config'); @@ -765,11 +766,13 @@ describe('attachUserAndCompany utility test', () => { }); }); -describe('addOrUpdateTagToCompany utility test', () => { +describe('addOrUpdateTagsToCompany utility test', () => { it('Should successfully add tags to company', async () => { const message = { - traits: { - tags: ['tag1', 'tag2'], + context: { + traits: { + tags: ['tag1', 'tag2'], + }, }, }; const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; @@ -786,7 +789,7 @@ describe('addOrUpdateTagToCompany utility test', () => { }); axios.post.mockClear(); - await addOrUpdateTagToCompany(message, destination, id); + await addOrUpdateTagsToCompany(message, destination, id); expect(axios.post).toHaveBeenCalledTimes(2); @@ -809,8 +812,10 @@ describe('addOrUpdateTagToCompany utility test', () => { it('Should throw an error in case if axios calls returns an error', async () => { const message = { - traits: { - tags: ['tag1'], + context: { + traits: { + tags: ['tag1'], + }, }, }; const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; @@ -832,7 +837,7 @@ describe('addOrUpdateTagToCompany utility test', () => { try { axios.post.mockClear(); - await addOrUpdateTagToCompany(message, destination, id); + await addOrUpdateTagsToCompany(message, destination, id); } catch (error) { expect(error.message).toEqual( `Unable to Add or Update the Tag to Company due to : [{"code":"unauthorized","message":"Access Token Invalid"}]`, @@ -846,7 +851,7 @@ describe('addOrUpdateTagToCompany utility test', () => { const id = 'companyId'; axios.post.mockClear(); - await addOrUpdateTagToCompany(message, destination, id); + await addOrUpdateTagsToCompany(message, destination, id); expect(axios.post).not.toHaveBeenCalled(); }); diff --git a/test/integrations/destinations/intercom/network.ts b/test/integrations/destinations/intercom/network.ts index 5fa8ac6e96..3267bc7495 100644 --- a/test/integrations/destinations/intercom/network.ts +++ b/test/integrations/destinations/intercom/network.ts @@ -43,6 +43,141 @@ const companyPayload = { industry: 'CDP', }; +const v1Headers = { + 'Content-Type': 'application/json', + Authorization: 'Bearer abcd=', + Accept: 'application/json', + 'Intercom-Version': '1.4', +}; + +const companyData1 = { + company_id: 'test_company_id_wdasda', + name: 'rudderUpdate', + plan: 'basic', + size: 50, + industry: 'IT', + monthly_spend: 2131231, + remote_created_at: 1683017572, + custom_attributes: { + key1: 'val1', + employees: 450, + email: 'test@test.com', + }, +}; + +const companyData2 = { + company_id: 'test_company_id_wdasda', + name: 'rudderUpdate', + website: 'url', + plan: 'basic', + size: 50, + industry: 'IT', + monthly_spend: 2131231, + remote_created_at: 1683017572, + custom_attributes: { + key1: 'val1', + employees: 450, + email: 'test@test.com', + 'key2.a': 'a', + 'key2.b': 'b', + 'key3[0]': 1, + 'key3[1]': 2, + 'key3[2]': 3, + key4: null, + }, +}; + +const companyData3 = { + company_id: 'test_company_id', + name: 'RudderStack', + website: 'www.rudderstack.com', + plan: 'enterprise', + size: 500, + industry: 'CDP', + monthly_spend: 2131231, + custom_attributes: { + email: 'comanyemail@abc.com', + }, +}; + +const userData1 = { + user_id: 'sdfrsdfsdfsf', + companies: [ + { + company_id: 'test_company_id_wdasda', + name: 'rudderUpdate', + }, + ], +}; + +const userData2 = { + email: 'testUser@test.com', + companies: [ + { + company_id: 'test_company_id_wdasda', + name: 'rudderUpdate', + }, + ], +}; + +const userData3 = { + user_id: 'sdfrsdfsdfsf', + email: 'testUser@test.com', + companies: [ + { + company_id: 'test_company_id_wdasda', + name: 'rudderUpdate', + }, + ], +}; + +const createCompanyDummyResp = { + type: 'company', + company_id: 'test_company_id_wdasda', + id: '657264e9018c0a647s45', + name: 'rudderUpdate', + website: 'url', + plan: 'basic', + size: 50, + industry: 'IT', + monthly_spend: 2131231, + remote_created_at: 1683017572, + created_at: 1701930212, + updated_at: 1701930212, + custom_attributes: { + key1: 'val1', + employees: 450, + email: 'test@test.com', + }, +}; + +const attachUserDummyResp = { + type: 'user', + id: '6662e5abd27951dd35e024e9', + user_id: 'user123', + anonymous: false, + email: 'test+5@rudderlabs.com', + app_id: '1234', + companies: { + type: 'company.list', + companies: [ + { + type: 'company', + company_id: 'company_id', + id: '6664ec390b9416d083be97fc', + name: 'Company', + }, + ], + }, + created_at: 1717757355, + updated_at: 1717890105, + tags: { + type: 'tag.list', + tags: [], + }, + custom_attributes: {}, +}; + const deleteNwData = [ { httpReq: { @@ -597,5 +732,186 @@ const deliveryCallsData = [ status: 504, }, }, + { + httpReq: { + method: 'post', + url: 'https://api.eu.intercom.io/contacts/70701240741e45d040/companies', + data: { + id: '657264e9018c0a647s45', + }, + headers: commonHeaders, + }, + httpRes: { + status: 200, + data: { + type: 'company', + company_id: 'rudderlabs', + id: '657264e9018c0a647s45', + name: 'RudderStack', + website: 'www.rudderstack.com', + plan: 'enterprise', + size: 500, + industry: 'CDP', + remote_created_at: 1374138000, + created_at: 1701930212, + updated_at: 1701930212, + }, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/companies', + data: companyPayload, + headers: commonHeaders, + }, + httpRes: { + status: 200, + data: { + type: 'company', + company_id: 'rudderlabs', + id: '657264e9018c0a647s45', + name: 'RudderStack', + website: 'www.rudderstack.com', + plan: 'enterprise', + size: 500, + industry: 'CDP', + remote_created_at: 1374138000, + created_at: 1701930212, + updated_at: 1701930212, + }, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/users', + data: { + user_id: 'user@5', + email: 'test+5@rudderlabs.com', + companies: [ + { + company_id: 'rudderlabs', + name: 'RudderStack', + }, + ], + }, + headers: commonHeaders, + }, + httpRes: { + status: 200, + data: { + type: 'company', + company_id: 'rudderlabs', + id: '657264e9018c0a647s45', + name: 'RudderStack', + website: 'www.rudderstack.com', + plan: 'enterprise', + size: 500, + industry: 'CDP', + remote_created_at: 1374138000, + created_at: 1701930212, + updated_at: 1701930212, + companies: { + type: 'company.list', + companies: [ + { + type: 'company', + company_id: 'rudderlabs', + id: '657264e9018c0a647s45', + name: 'RudderStack', + }, + ], + }, + }, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/companies', + data: companyData1, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: createCompanyDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/companies', + data: { + ...companyData1, + website: 'url', + }, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: createCompanyDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/companies', + data: companyData2, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: createCompanyDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/companies', + data: companyData3, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: createCompanyDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/users', + data: userData1, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: attachUserDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/users', + data: userData2, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: attachUserDummyResp, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.intercom.io/users', + data: userData3, + headers: v1Headers, + }, + httpRes: { + status: 200, + data: attachUserDummyResp, + }, + }, ]; export const networkCallsData = [...deleteNwData, ...deliveryCallsData]; diff --git a/test/integrations/destinations/intercom/router/data.ts b/test/integrations/destinations/intercom/router/data.ts index 2ce8621ca1..5fe7d71ea5 100644 --- a/test/integrations/destinations/intercom/router/data.ts +++ b/test/integrations/destinations/intercom/router/data.ts @@ -335,7 +335,7 @@ export const data = [ jobId: 3, }, ], - statusCode: 200, + statusCode: 299, }, { batched: false, @@ -787,7 +787,7 @@ export const data = [ jobId: 3, }, ], - statusCode: 200, + statusCode: 299, }, ], }, From 682414173a5cfbfcda96215841b75daaa5bd668e Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 10 Jun 2024 12:42:16 +0530 Subject: [PATCH 3/7] feat: added some tests --- src/cdk/v2/destinations/intercom/utils.js | 2 +- .../v2/destinations/intercom/utils.test.js | 104 ++++++++++++++++++ .../destinations/intercom/network.ts | 46 ++++++++ .../destinations/intercom/router/data.ts | 87 +++++++++++++++ 4 files changed, 238 insertions(+), 1 deletion(-) diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index 7ada43cf37..28b21427cb 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -406,7 +406,7 @@ const attachContactToCompany = async (payload, endpoint, destination) => { const processedResponse = processAxiosResponse(response); if (!isHttpStatusSuccess(processedResponse.status)) { throw new NetworkError( - `Unable to attach Contact to Company due to : ${JSON.stringify( + `Unable to attach Contact or User to Company due to : ${JSON.stringify( processedResponse?.response?.errors, )}`, processedResponse?.status, diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index cdc01cb1ad..d494f10c51 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -766,6 +766,110 @@ describe('attachUserAndCompany utility test', () => { }); }); +describe('attachContactToCompany utility test', () => { + it('Should successfully attach contact to company for apiVersion v2', async () => { + const payload = { + id: 'company123', + }; + const endpoint = 'https://api.intercom.io/contacts/contact123/companies'; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us', apiVersion: 'v2' } }; + + axios.post.mockResolvedValue({ + status: 200, + data: { + type: 'company', + id: 'contact123', + company_id: 'company123', + }, + }); + + await attachContactToCompany(payload, endpoint, destination); + + expect(axios.post).toHaveBeenCalledWith( + endpoint, + JSON.stringify(payload), + expect.objectContaining({ + headers: getHeaders(destination, 'v2'), + }), + ); + }); + + it('Should successfully attach contact to company for apiVersion v1', async () => { + const payload = { + user_id: 'user123', + companies: [ + { + company_id: 'company123', + name: 'Company', + }, + ], + }; + const endpoint = 'https://api.intercom.io/users'; + const destination = { Config: { apiKey: 'testApiKey', apiVersion: 'v1' } }; + + axios.post.mockResolvedValue({ + status: 200, + data: { + id: 'contact123', + user_id: 'user123', + companies: { + type: 'companies.list', + companies: [ + { + type: 'company', + company_id: 'company123', + id: '123', + name: 'Company', + }, + ], + }, + }, + }); + + await attachContactToCompany(payload, endpoint, destination); + + expect(axios.post).toHaveBeenCalledWith( + endpoint, + JSON.stringify(payload), + expect.objectContaining({ + headers: getHeaders(destination, 'v1'), + }), + ); + }); + + it('Should throw a network error during attachment', async () => { + const payload = { + id: 'company123', + }; + const endpoint = 'https://api.intercom.io/contacts/contact123/companies'; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us', apiVersion: 'v2' } }; + + axios.post.mockRejectedValue({ + response: { + status: 404, + data: { + type: 'error.list', + request_id: '123', + errors: [ + { + code: 'company_not_found', + message: 'Company Not Found', + }, + ], + }, + }, + }); + + try { + await attachContactToCompany(payload, endpoint, destination); + } catch (error) { + expect(error.message).toEqual( + 'Unable to attach Contact or User to Company due to : [{"code":"company_not_found","message":"Company Not Found"}]', + ); + } + }); +}); + describe('addOrUpdateTagsToCompany utility test', () => { it('Should successfully add tags to company', async () => { const message = { diff --git a/test/integrations/destinations/intercom/network.ts b/test/integrations/destinations/intercom/network.ts index 3267bc7495..69f5ea1247 100644 --- a/test/integrations/destinations/intercom/network.ts +++ b/test/integrations/destinations/intercom/network.ts @@ -913,5 +913,51 @@ const deliveryCallsData = [ data: attachUserDummyResp, }, }, + { + httpReq: { + method: 'post', + url: 'https://api.eu.intercom.io/tags', + data: { + name: 'tag1', + companies: [ + { + id: '657264e9018c0a647s45', + }, + ], + }, + headers: commonHeaders, + }, + httpRes: { + status: 200, + data: { + type: 'tag', + name: 'tag1', + id: '123', + }, + }, + }, + { + httpReq: { + method: 'post', + url: 'https://api.eu.intercom.io/tags', + data: { + name: 'tag2', + companies: [ + { + id: '657264e9018c0a647s45', + }, + ], + }, + headers: commonHeaders, + }, + httpRes: { + status: 200, + data: { + type: 'tag', + name: 'tag2', + id: '123', + }, + }, + }, ]; export const networkCallsData = [...deleteNwData, ...deliveryCallsData]; diff --git a/test/integrations/destinations/intercom/router/data.ts b/test/integrations/destinations/intercom/router/data.ts index 5fe7d71ea5..e56a0e7c2d 100644 --- a/test/integrations/destinations/intercom/router/data.ts +++ b/test/integrations/destinations/intercom/router/data.ts @@ -135,6 +135,49 @@ export const data = [ jobId: 3, }, }, + { + message: { + userId: 'user@5', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + tags: ['tag1', 'tag2'], + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + destination: { + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v2', + apiServer: 'eu', + sendAnonymousId: false, + }, + }, + metadata: { + jobId: 5, + }, + }, { message: { userId: 'user@6', @@ -337,6 +380,50 @@ export const data = [ ], statusCode: 299, }, + { + batched: false, + batchedRequest: { + body: { + JSON: { + id: '657264e9018c0a647s45', + }, + XML: {}, + FORM: {}, + JSON_ARRAY: {}, + }, + endpoint: 'https://api.eu.intercom.io/contacts/70701240741e45d040/companies', + files: {}, + headers: { + Authorization: 'Bearer testApiKey', + 'Content-Type': 'application/json', + Accept: 'application/json', + 'Intercom-Version': '2.10', + }, + method: 'POST', + params: {}, + type: 'REST', + version: '1', + }, + destination: { + Config: { + apiKey: 'testApiKey', + apiServer: 'eu', + apiVersion: 'v2', + sendAnonymousId: false, + }, + DestinationDefinition: { + Config: { + cdkV2Enabled: true, + }, + }, + }, + metadata: [ + { + jobId: 5, + }, + ], + statusCode: 299, + }, { batched: false, error: From 2a083ed370757428b05f82d1d56fb5b8924a4be6 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Tue, 11 Jun 2024 19:57:39 +0530 Subject: [PATCH 4/7] feat: added error handler --- src/cdk/v2/destinations/intercom/utils.js | 48 +++++++----- .../v2/destinations/intercom/utils.test.js | 73 ++++++++++++++++++- 2 files changed, 98 insertions(+), 23 deletions(-) diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index 28b21427cb..af837e9cee 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -1,6 +1,10 @@ const md5 = require('md5'); const get = require('get-value'); -const { NetworkError } = require('@rudderstack/integrations-lib'); +const { + NetworkError, + ConfigurationError, + InstrumentationError, +} = require('@rudderstack/integrations-lib'); const tags = require('../../../../v0/util/tags'); const { httpPOST } = require('../../../../adapters/network'); const { @@ -30,6 +34,27 @@ const { TAGS_ENDPOINT, } = require('./config'); +const intercomErrorHandler = (message, processedResponse) => { + const errorMessages = JSON.stringify(processedResponse?.response?.errors); + if (processedResponse?.status === 400) { + throw new InstrumentationError(`${message} : ${errorMessages}`); + } + if (processedResponse?.status === 401) { + throw new ConfigurationError(`${message} : ${errorMessages}`); + } + if (processedResponse?.status === 404) { + throw new InstrumentationError(`${message} : ${errorMessages}`); + } + throw new NetworkError( + `${message} : ${errorMessages}`, + processedResponse?.status, + { + [tags]: getDynamicErrorType(processedResponse?.status), + }, + processedResponse, + ); +}; + /** * Returns destination request headers * @param {*} destination @@ -405,16 +430,7 @@ const attachContactToCompany = async (payload, endpoint, destination) => { const processedResponse = processAxiosResponse(response); if (!isHttpStatusSuccess(processedResponse.status)) { - throw new NetworkError( - `Unable to attach Contact or User to Company due to : ${JSON.stringify( - processedResponse?.response?.errors, - )}`, - processedResponse?.status, - { - [tags]: getDynamicErrorType(processedResponse?.status), - }, - processedResponse, - ); + intercomErrorHandler('Unable to attach Contact or User to Company due to', processedResponse); } }; @@ -461,14 +477,8 @@ const addOrUpdateTagsToCompany = async (message, destination, id) => { ); const processedResponse = processAxiosResponse(response); if (!isHttpStatusSuccess(processedResponse.status)) { - throw new NetworkError( - `Unable to Add or Update the Tag to Company due to : ${JSON.stringify( - processedResponse?.response?.errors, - )}`, - processedResponse?.status, - { - [tags]: getDynamicErrorType(processedResponse?.status), - }, + intercomErrorHandler( + 'Unable to Add or Update the Tag to Company due to', processedResponse, ); } diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index d494f10c51..65d8bbd1c0 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -837,7 +837,7 @@ describe('attachContactToCompany utility test', () => { ); }); - it('Should throw a network error during attachment', async () => { + it('Should throw error for invalid company during attachment', async () => { const payload = { id: 'company123', }; @@ -868,6 +868,36 @@ describe('attachContactToCompany utility test', () => { ); } }); + + it('Should throw error for faulty payload during attachment', async () => { + const payload = {}; + const endpoint = 'https://api.intercom.io/contacts/contact123/companies'; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us', apiVersion: 'v2' } }; + + axios.post.mockRejectedValue({ + response: { + status: 400, + data: { + type: 'error.list', + request_id: '123', + errors: [ + { + code: 'parameter_not_found', + message: 'company not specified', + }, + ], + }, + }, + }); + + try { + await attachContactToCompany(payload, endpoint, destination); + } catch (error) { + expect(error.message).toEqual( + 'Unable to attach Contact or User to Company due to : [{"code":"parameter_not_found","message":"company not specified"}]', + ); + } + }); }); describe('addOrUpdateTagsToCompany utility test', () => { @@ -926,10 +956,10 @@ describe('addOrUpdateTagsToCompany utility test', () => { const id = 'companyId'; axios.post.mockRejectedValue({ - status: 400, + status: 401, data: { type: 'error.list', - request_id: 'request_400', + request_id: 'request_401', errors: [ { code: 'unauthorized', @@ -944,7 +974,42 @@ describe('addOrUpdateTagsToCompany utility test', () => { await addOrUpdateTagsToCompany(message, destination, id); } catch (error) { expect(error.message).toEqual( - `Unable to Add or Update the Tag to Company due to : [{"code":"unauthorized","message":"Access Token Invalid"}]`, + `Unable to Add or Update the Tag to Company due to : [{\"code\":\"unauthorized\",\"message\":\"Access Token Invalid\"}]`, + ); + } + }); + + it('Should throw a network error in case if axios calls returns an error', async () => { + const message = { + context: { + traits: { + tags: ['tag1'], + }, + }, + }; + const destination = { Config: { apiKey: 'testApiKey', apiServer: 'us' } }; + const id = 'companyId'; + + axios.post.mockRejectedValue({ + status: 429, + data: { + type: 'error.list', + request_id: 'request_429', + errors: [ + { + code: 'rate_limit_exceeded', + message: 'You have exceeded the rate limit. Please try again later.', + }, + ], + }, + }); + + try { + axios.post.mockClear(); + await addOrUpdateTagsToCompany(message, destination, id); + } catch (error) { + expect(error.message).toEqual( + `Unable to Add or Update the Tag to Company due to : [{\"code\":\"rate_limit_exceeded\",\"message\":\"You have exceeded the rate limit. Please try again later.\"}]`, ); } }); From e822bce9e582bdb500454694d52002d4f7efa3cb Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Thu, 13 Jun 2024 16:52:01 +0530 Subject: [PATCH 5/7] fix: addressing comments --- src/cdk/v2/destinations/intercom/utils.js | 35 +++++++++++++------ .../v2/destinations/intercom/utils.test.js | 8 ++--- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index af837e9cee..7e609d5c96 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -34,22 +34,34 @@ const { TAGS_ENDPOINT, } = require('./config'); +/** + * method to handle error during api call + * ref docs: https://developers.intercom.com/docs/references/rest-api/errors/error-codes/ + * https://developers.intercom.com/docs/references/rest-api/errors/error-objects/ + * https://developers.intercom.com/docs/references/rest-api/errors/http-responses/ + * e.g. + * 400 - code: parameter_not_found (or parameter_invalid), message: company not specified + * 401 - code: unauthorized, message: Access Token Invalid + * 404 - code: company_not_found, message: Company Not Found + * @param {*} message + * @param {*} processedResponse + */ const intercomErrorHandler = (message, processedResponse) => { - const errorMessages = JSON.stringify(processedResponse?.response?.errors); - if (processedResponse?.status === 400) { + const errorMessages = JSON.stringify(processedResponse.response); + if (processedResponse.status === 400) { throw new InstrumentationError(`${message} : ${errorMessages}`); } - if (processedResponse?.status === 401) { + if (processedResponse.status === 401) { throw new ConfigurationError(`${message} : ${errorMessages}`); } - if (processedResponse?.status === 404) { + if (processedResponse.status === 404) { throw new InstrumentationError(`${message} : ${errorMessages}`); } throw new NetworkError( `${message} : ${errorMessages}`, - processedResponse?.status, + processedResponse.status, { - [tags]: getDynamicErrorType(processedResponse?.status), + [tags]: getDynamicErrorType(processedResponse.status), }, processedResponse, ); @@ -411,6 +423,12 @@ const attachContactToCompany = async (payload, endpoint, destination) => { if (apiVersion === 'v1') { endpointPath = '/users'; } + const commonStatTags = { + destType: 'intercom', + feature: 'transformation', + requestMethod: 'POST', + module: 'router', + }; const headers = getHeaders(destination, apiVersion); const finalPayload = JSON.stringify(removeUndefinedAndNullValues(payload)); const response = await httpPOST( @@ -420,11 +438,8 @@ const attachContactToCompany = async (payload, endpoint, destination) => { headers, }, { - destType: 'intercom', - feature: 'transformation', + ...commonStatTags, endpointPath, - requestMethod: 'POST', - module: 'router', }, ); diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index 65d8bbd1c0..2f7dac2583 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -864,7 +864,7 @@ describe('attachContactToCompany utility test', () => { await attachContactToCompany(payload, endpoint, destination); } catch (error) { expect(error.message).toEqual( - 'Unable to attach Contact or User to Company due to : [{"code":"company_not_found","message":"Company Not Found"}]', + 'Unable to attach Contact or User to Company due to : {"type":"error.list","request_id":"123","errors":[{"code":"company_not_found","message":"Company Not Found"}]}', ); } }); @@ -894,7 +894,7 @@ describe('attachContactToCompany utility test', () => { await attachContactToCompany(payload, endpoint, destination); } catch (error) { expect(error.message).toEqual( - 'Unable to attach Contact or User to Company due to : [{"code":"parameter_not_found","message":"company not specified"}]', + 'Unable to attach Contact or User to Company due to : {"type":"error.list","request_id":"123","errors":[{"code":"parameter_not_found","message":"company not specified"}]}', ); } }); @@ -974,7 +974,7 @@ describe('addOrUpdateTagsToCompany utility test', () => { await addOrUpdateTagsToCompany(message, destination, id); } catch (error) { expect(error.message).toEqual( - `Unable to Add or Update the Tag to Company due to : [{\"code\":\"unauthorized\",\"message\":\"Access Token Invalid\"}]`, + `Unable to Add or Update the Tag to Company due to : {"type":"error.list","request_id":"request_401","errors":[{"code":"unauthorized","message":"Access Token Invalid"}]}`, ); } }); @@ -1009,7 +1009,7 @@ describe('addOrUpdateTagsToCompany utility test', () => { await addOrUpdateTagsToCompany(message, destination, id); } catch (error) { expect(error.message).toEqual( - `Unable to Add or Update the Tag to Company due to : [{\"code\":\"rate_limit_exceeded\",\"message\":\"You have exceeded the rate limit. Please try again later.\"}]`, + `Unable to Add or Update the Tag to Company due to : {"type":"error.list","request_id":"request_429","errors":[{"code":"rate_limit_exceeded","message":"You have exceeded the rate limit. Please try again later."}]}`, ); } }); From 4dfe0791ef53ff92529e280231427cf7216e6844 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 17 Jun 2024 13:55:29 +0530 Subject: [PATCH 6/7] chore: refactoring tests --- .../destinations/intercom/router/data.ts | 1445 ++++++++--------- 1 file changed, 638 insertions(+), 807 deletions(-) diff --git a/test/integrations/destinations/intercom/router/data.ts b/test/integrations/destinations/intercom/router/data.ts index e56a0e7c2d..0d3cb4eb96 100644 --- a/test/integrations/destinations/intercom/router/data.ts +++ b/test/integrations/destinations/intercom/router/data.ts @@ -1,230 +1,613 @@ -export const data = [ +import { Destination, RouterTransformationRequest } from '../../../../../src/types'; +import { RouterTestData } from '../../../testTypes'; +import { generateMetadata } from '../../../testUtils'; + +const destination1: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiServer: 'standard', + apiVersion: 'v2', + sendAnonymousId: false, + updateLastRequestAt: true, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const destination2: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiServer: 'standard', + apiVersion: 'v2', + sendAnonymousId: false, + updateLastRequestAt: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const destination3: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v2', + apiServer: 'eu', + sendAnonymousId: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const destination4: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v1', + sendAnonymousId: false, + updateLastRequestAt: false, + collectContext: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const destination5: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: { + cdkV2Enabled: true, + }, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v1', + sendAnonymousId: false, + collectContext: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const routerRequest1: RouterTransformationRequest = { + input: [ + { + destination: destination1, + message: { + userId: 'user@1', + channel: 'web', + context: { + traits: { + age: 23, + email: 'test@rudderlabs.com', + phone: '+91 9999999999', + firstName: 'Test', + lastName: 'Rudderlabs', + address: 'california usa', + ownerId: '13', + }, + }, + type: 'identify', + integrations: { All: true }, + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(1), + }, + { + destination: destination2, + message: { + userId: 'user@3', + channel: 'web', + context: { + traits: { + age: 32, + email: 'test+3@rudderlabs.com', + phone: '+91 9399999999', + firstName: 'Test', + lastName: 'RudderStack', + ownerId: '15', + }, + }, + properties: { + revenue: { + amount: 1232, + currency: 'inr', + test: 123, + }, + price: { + amount: 3000, + currency: 'USD', + }, + }, + event: 'Product Viewed', + type: 'track', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(2), + }, + { + destination: destination3, + message: { + userId: 'user@5', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(3), + }, + { + destination: destination3, + message: { + userId: 'user@5', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + tags: ['tag1', 'tag2'], + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(5), + }, + { + destination: destination3, + message: { + userId: 'user@6', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + isOpenSource: true, + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(4), + }, + ], + destType: 'intercom', +}; + +const routerRequest2: RouterTransformationRequest = { + input: [ + { + destination: destination4, + message: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + channel: 'mobile', + context: { + app: { + build: '1.0', + name: 'Test_Example', + namespace: 'com.example.testapp', + version: '1.0', + }, + device: { + id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + manufacturer: 'Apple', + model: 'iPhone', + name: 'iPod touch (7th generation)', + type: 'iOS', + }, + library: { + name: 'test-ios-library', + version: '1.0.7', + }, + locale: 'en-US', + network: { + bluetooth: false, + carrier: 'unavailable', + cellular: false, + wifi: true, + }, + os: { + name: 'iOS', + version: '14.0', + }, + screen: { + density: 2, + height: 320, + width: 568, + }, + timezone: 'Asia/Kolkata', + traits: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + name: 'Test Name', + firstName: 'Test', + lastName: 'Name', + createdAt: '2020-09-30T19:11:00.337Z', + userId: 'test_user_id_1', + email: 'test_1@test.com', + phone: '9876543210', + key1: 'value1', + }, + userAgent: 'unknown', + }, + event: 'Test Event 2', + integrations: { + All: true, + }, + messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', + originalTimestamp: '2020-09-30T19:11:00.337Z', + receivedAt: '2020-10-01T00:41:11.369+05:30', + request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', + sentAt: '2020-09-30T19:11:10.382Z', + timestamp: '2020-10-01T00:41:01.324+05:30', + type: 'identify', + }, + metadata: generateMetadata(1), + }, + { + destination: destination4, + message: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + channel: 'mobile', + context: { + app: { + build: '1.0', + name: 'Test_Example', + namespace: 'com.example.testapp', + version: '1.0', + }, + device: { + id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + manufacturer: 'Apple', + model: 'iPhone', + name: 'iPod touch (7th generation)', + type: 'iOS', + }, + library: { + name: 'test-ios-library', + version: '1.0.7', + }, + locale: 'en-US', + network: { + bluetooth: false, + carrier: 'unavailable', + cellular: false, + wifi: true, + }, + os: { + name: 'iOS', + version: '14.0', + }, + screen: { + density: 2, + height: 320, + width: 568, + }, + timezone: 'Asia/Kolkata', + traits: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + firstName: 'Test', + lastName: 'Name', + createdAt: '2020-09-30T19:11:00.337Z', + email: 'test_1@test.com', + phone: '9876543210', + key1: 'value1', + }, + userAgent: 'unknown', + }, + event: 'Test Event 2', + integrations: { + All: true, + }, + messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', + originalTimestamp: '2020-09-30T19:11:00.337Z', + receivedAt: '2020-10-01T00:41:11.369+05:30', + request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', + sentAt: '2020-09-30T19:11:10.382Z', + timestamp: '2020-10-01T00:41:01.324+05:30', + type: 'identify', + }, + metadata: generateMetadata(2), + }, + { + destination: destination5, + message: { + userId: 'user@5', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(3), + }, + ], + destType: 'intercom', +}; + +const routerRequest3: RouterTransformationRequest = { + input: [ + { + destination: destination4, + message: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + channel: 'mobile', + context: { + app: { + build: '1.0', + name: 'Test_Example', + namespace: 'com.example.testapp', + version: '1.0', + }, + device: { + id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + manufacturer: 'Apple', + model: 'iPhone', + name: 'iPod touch (7th generation)', + type: 'iOS', + }, + library: { + name: 'test-ios-library', + version: '1.0.7', + }, + locale: 'en-US', + network: { + bluetooth: false, + carrier: 'unavailable', + cellular: false, + wifi: true, + }, + os: { + name: 'iOS', + version: '14.0', + }, + screen: { + density: 2, + height: 320, + width: 568, + }, + timezone: 'Asia/Kolkata', + traits: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + name: 'Test Name', + firstName: 'Test', + lastName: 'Name', + createdAt: '2020-09-30T19:11:00.337Z', + userId: 'test_user_id_1', + email: 'test_1@test.com', + phone: '9876543210', + key1: 'value1', + }, + userAgent: 'unknown', + }, + event: 'Test Event 2', + integrations: { + All: true, + }, + messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', + originalTimestamp: '2020-09-30T19:11:00.337Z', + receivedAt: '2020-10-01T00:41:11.369+05:30', + request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', + sentAt: '2020-09-30T19:11:10.382Z', + timestamp: '2020-10-01T00:41:01.324+05:30', + type: 'identify', + }, + metadata: generateMetadata(1), + }, + { + destination: destination4, + message: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + channel: 'mobile', + context: { + app: { + build: '1.0', + name: 'Test_Example', + namespace: 'com.example.testapp', + version: '1.0', + }, + device: { + id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + manufacturer: 'Apple', + model: 'iPhone', + name: 'iPod touch (7th generation)', + type: 'iOS', + }, + library: { + name: 'test-ios-library', + version: '1.0.7', + }, + locale: 'en-US', + network: { + bluetooth: false, + carrier: 'unavailable', + cellular: false, + wifi: true, + }, + os: { + name: 'iOS', + version: '14.0', + }, + screen: { + density: 2, + height: 320, + width: 568, + }, + timezone: 'Asia/Kolkata', + traits: { + anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', + firstName: 'Test', + lastName: 'Name', + createdAt: '2020-09-30T19:11:00.337Z', + email: 'test_1@test.com', + phone: '9876543210', + key1: 'value1', + }, + userAgent: 'unknown', + }, + event: 'Test Event 2', + integrations: { + All: true, + }, + messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', + originalTimestamp: '2020-09-30T19:11:00.337Z', + receivedAt: '2020-10-01T00:41:11.369+05:30', + request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', + sentAt: '2020-09-30T19:11:10.382Z', + timestamp: '2020-10-01T00:41:01.324+05:30', + type: 'identify', + }, + metadata: generateMetadata(2), + }, + { + destination: destination5, + message: { + userId: 'user@5', + groupId: 'rudderlabs', + channel: 'web', + context: { + traits: { + email: 'test+5@rudderlabs.com', + phone: '+91 9599999999', + firstName: 'John', + lastName: 'Snow', + ownerId: '17', + }, + }, + traits: { + name: 'RudderStack', + size: 500, + website: 'www.rudderstack.com', + industry: 'CDP', + plan: 'enterprise', + }, + type: 'group', + originalTimestamp: '2023-11-10T14:42:44.724Z', + timestamp: '2023-11-22T10:12:44.757+05:30', + }, + metadata: generateMetadata(3), + }, + ], + destType: 'intercom', +}; + +export const data: RouterTestData[] = [ { + id: 'Intercom-router-test-1', + scenario: 'Framework', + successCriteria: 'Some events should be transformed successfully and some should fail', name: 'intercom', - description: 'Intercom router tests', + description: 'Intercom router tests 1', feature: 'router', module: 'destination', version: 'v0', input: { request: { - body: { - input: [ - { - message: { - userId: 'user@1', - channel: 'web', - context: { - traits: { - age: 23, - email: 'test@rudderlabs.com', - phone: '+91 9999999999', - firstName: 'Test', - lastName: 'Rudderlabs', - address: 'california usa', - ownerId: '13', - }, - }, - type: 'identify', - integrations: { All: true }, - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiServer: 'standard', - apiVersion: 'v2', - sendAnonymousId: false, - updateLastRequestAt: true, - }, - }, - metadata: { jobId: 1 }, - }, - { - message: { - userId: 'user@3', - channel: 'web', - context: { - traits: { - age: 32, - email: 'test+3@rudderlabs.com', - phone: '+91 9399999999', - firstName: 'Test', - lastName: 'RudderStack', - ownerId: '15', - }, - }, - properties: { - revenue: { - amount: 1232, - currency: 'inr', - test: 123, - }, - price: { - amount: 3000, - currency: 'USD', - }, - }, - event: 'Product Viewed', - type: 'track', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiServer: 'standard', - apiVersion: 'v2', - sendAnonymousId: false, - updateLastRequestAt: false, - }, - }, - metadata: { - jobId: 2, - }, - }, - { - message: { - userId: 'user@5', - groupId: 'rudderlabs', - channel: 'web', - context: { - traits: { - email: 'test+5@rudderlabs.com', - phone: '+91 9599999999', - firstName: 'John', - lastName: 'Snow', - ownerId: '17', - }, - }, - traits: { - name: 'RudderStack', - size: 500, - website: 'www.rudderstack.com', - industry: 'CDP', - plan: 'enterprise', - }, - type: 'group', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v2', - apiServer: 'eu', - sendAnonymousId: false, - }, - }, - metadata: { - jobId: 3, - }, - }, - { - message: { - userId: 'user@5', - groupId: 'rudderlabs', - channel: 'web', - context: { - traits: { - email: 'test+5@rudderlabs.com', - phone: '+91 9599999999', - firstName: 'John', - lastName: 'Snow', - ownerId: '17', - tags: ['tag1', 'tag2'], - }, - }, - traits: { - name: 'RudderStack', - size: 500, - website: 'www.rudderstack.com', - industry: 'CDP', - plan: 'enterprise', - }, - type: 'group', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v2', - apiServer: 'eu', - sendAnonymousId: false, - }, - }, - metadata: { - jobId: 5, - }, - }, - { - message: { - userId: 'user@6', - groupId: 'rudderlabs', - channel: 'web', - context: { - traits: { - email: 'test+5@rudderlabs.com', - phone: '+91 9599999999', - firstName: 'John', - lastName: 'Snow', - ownerId: '17', - }, - }, - traits: { - name: 'RudderStack', - size: 500, - website: 'www.rudderstack.com', - industry: 'CDP', - plan: 'enterprise', - isOpenSource: true, - }, - type: 'group', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v2', - apiServer: 'eu', - sendAnonymousId: false, - }, - }, - metadata: { - jobId: 4, - }, - }, - ], - destType: 'intercom', - }, - method: 'POST', + body: routerRequest1, }, }, output: { @@ -264,21 +647,8 @@ export const data = [ type: 'REST', version: '1', }, - destination: { - Config: { - apiKey: 'testApiKey', - apiServer: 'standard', - apiVersion: 'v2', - sendAnonymousId: false, - updateLastRequestAt: true, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [{ jobId: 1 }], + destination: destination1, + metadata: [generateMetadata(1)], statusCode: 200, }, { @@ -319,21 +689,8 @@ export const data = [ type: 'REST', version: '1', }, - destination: { - Config: { - apiKey: 'testApiKey', - apiServer: 'standard', - apiVersion: 'v2', - sendAnonymousId: false, - updateLastRequestAt: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [{ jobId: 2 }], + destination: destination2, + metadata: [generateMetadata(2)], statusCode: 200, }, { @@ -360,24 +717,8 @@ export const data = [ type: 'REST', version: '1', }, - destination: { - Config: { - apiKey: 'testApiKey', - apiServer: 'eu', - apiVersion: 'v2', - sendAnonymousId: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [ - { - jobId: 3, - }, - ], + destination: destination3, + metadata: [generateMetadata(3)], statusCode: 299, }, { @@ -404,24 +745,8 @@ export const data = [ type: 'REST', version: '1', }, - destination: { - Config: { - apiKey: 'testApiKey', - apiServer: 'eu', - apiVersion: 'v2', - sendAnonymousId: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [ - { - jobId: 5, - }, - ], + destination: destination3, + metadata: [generateMetadata(5)], statusCode: 299, }, { @@ -435,25 +760,11 @@ export const data = [ feature: 'router', implementation: 'cdkV2', module: 'destination', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', }, - destination: { - Config: { - apiKey: 'testApiKey', - apiServer: 'eu', - apiVersion: 'v2', - sendAnonymousId: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [ - { - jobId: 4, - }, - ], + destination: destination3, + metadata: [generateMetadata(4)], statusCode: 401, }, ], @@ -462,222 +773,17 @@ export const data = [ }, }, { + id: 'Intercom-router-test-2', + scenario: 'Framework', + successCriteria: 'Some events should be transformed successfully and some should fail', name: 'intercom', - description: 'Test 0', + description: 'Intercom router tests 2', feature: 'router', module: 'destination', version: 'v0', input: { request: { - body: { - input: [ - { - message: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - channel: 'mobile', - context: { - app: { - build: '1.0', - name: 'Test_Example', - namespace: 'com.example.testapp', - version: '1.0', - }, - device: { - id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - manufacturer: 'Apple', - model: 'iPhone', - name: 'iPod touch (7th generation)', - type: 'iOS', - }, - library: { - name: 'test-ios-library', - version: '1.0.7', - }, - locale: 'en-US', - network: { - bluetooth: false, - carrier: 'unavailable', - cellular: false, - wifi: true, - }, - os: { - name: 'iOS', - version: '14.0', - }, - screen: { - density: 2, - height: 320, - width: 568, - }, - timezone: 'Asia/Kolkata', - traits: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - name: 'Test Name', - firstName: 'Test', - lastName: 'Name', - createdAt: '2020-09-30T19:11:00.337Z', - userId: 'test_user_id_1', - email: 'test_1@test.com', - phone: '9876543210', - key1: 'value1', - }, - userAgent: 'unknown', - }, - event: 'Test Event 2', - integrations: { - All: true, - }, - messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', - originalTimestamp: '2020-09-30T19:11:00.337Z', - receivedAt: '2020-10-01T00:41:11.369+05:30', - request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', - sentAt: '2020-09-30T19:11:10.382Z', - timestamp: '2020-10-01T00:41:01.324+05:30', - type: 'identify', - }, - metadata: { - jobId: 1, - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - updateLastRequestAt: false, - collectContext: false, - }, - }, - }, - { - message: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - channel: 'mobile', - context: { - app: { - build: '1.0', - name: 'Test_Example', - namespace: 'com.example.testapp', - version: '1.0', - }, - device: { - id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - manufacturer: 'Apple', - model: 'iPhone', - name: 'iPod touch (7th generation)', - type: 'iOS', - }, - library: { - name: 'test-ios-library', - version: '1.0.7', - }, - locale: 'en-US', - network: { - bluetooth: false, - carrier: 'unavailable', - cellular: false, - wifi: true, - }, - os: { - name: 'iOS', - version: '14.0', - }, - screen: { - density: 2, - height: 320, - width: 568, - }, - timezone: 'Asia/Kolkata', - traits: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - firstName: 'Test', - lastName: 'Name', - createdAt: '2020-09-30T19:11:00.337Z', - email: 'test_1@test.com', - phone: '9876543210', - key1: 'value1', - }, - userAgent: 'unknown', - }, - event: 'Test Event 2', - integrations: { - All: true, - }, - messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', - originalTimestamp: '2020-09-30T19:11:00.337Z', - receivedAt: '2020-10-01T00:41:11.369+05:30', - request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', - sentAt: '2020-09-30T19:11:10.382Z', - timestamp: '2020-10-01T00:41:01.324+05:30', - type: 'identify', - }, - metadata: { - jobId: 2, - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - updateLastRequestAt: false, - collectContext: false, - }, - }, - }, - { - message: { - userId: 'user@5', - groupId: 'rudderlabs', - channel: 'web', - context: { - traits: { - email: 'test+5@rudderlabs.com', - phone: '+91 9599999999', - firstName: 'John', - lastName: 'Snow', - ownerId: '17', - }, - }, - traits: { - name: 'RudderStack', - size: 500, - website: 'www.rudderstack.com', - industry: 'CDP', - plan: 'enterprise', - }, - type: 'group', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - collectContext: false, - }, - }, - metadata: { - jobId: 3, - }, - }, - ], - destType: 'intercom', - }, + body: routerRequest2, }, }, output: { @@ -719,27 +825,10 @@ export const data = [ files: {}, userId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', }, - metadata: [ - { - jobId: 1, - }, - ], + metadata: [generateMetadata(1)], batched: false, statusCode: 200, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - updateLastRequestAt: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, + destination: destination4, }, { batchedRequest: { @@ -774,27 +863,10 @@ export const data = [ files: {}, userId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', }, - metadata: [ - { - jobId: 2, - }, - ], + metadata: [generateMetadata(2)], batched: false, statusCode: 200, - destination: { - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - updateLastRequestAt: false, - }, - }, + destination: destination4, }, { batched: false, @@ -856,24 +928,8 @@ export const data = [ version: '1', }, ], - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - }, - DestinationDefinition: { - Config: { - cdkV2Enabled: true, - }, - }, - }, - metadata: [ - { - jobId: 3, - }, - ], + destination: destination5, + metadata: [generateMetadata(3)], statusCode: 299, }, ], @@ -882,207 +938,17 @@ export const data = [ }, }, { + id: 'Intercom-router-test-3', + scenario: 'Framework', + successCriteria: 'Some events should be transformed successfully and some should fail', name: 'intercom', - description: 'Test 0', + description: 'Intercom router tests 3', feature: 'router', module: 'destination', version: 'v0', input: { request: { - body: { - input: [ - { - message: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - channel: 'mobile', - context: { - app: { - build: '1.0', - name: 'Test_Example', - namespace: 'com.example.testapp', - version: '1.0', - }, - device: { - id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - manufacturer: 'Apple', - model: 'iPhone', - name: 'iPod touch (7th generation)', - type: 'iOS', - }, - library: { - name: 'test-ios-library', - version: '1.0.7', - }, - locale: 'en-US', - network: { - bluetooth: false, - carrier: 'unavailable', - cellular: false, - wifi: true, - }, - os: { - name: 'iOS', - version: '14.0', - }, - screen: { - density: 2, - height: 320, - width: 568, - }, - timezone: 'Asia/Kolkata', - traits: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - name: 'Test Name', - firstName: 'Test', - lastName: 'Name', - createdAt: '2020-09-30T19:11:00.337Z', - userId: 'test_user_id_1', - email: 'test_1@test.com', - phone: '9876543210', - key1: 'value1', - }, - userAgent: 'unknown', - }, - event: 'Test Event 2', - integrations: { - All: true, - }, - messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', - originalTimestamp: '2020-09-30T19:11:00.337Z', - receivedAt: '2020-10-01T00:41:11.369+05:30', - request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', - sentAt: '2020-09-30T19:11:10.382Z', - timestamp: '2020-10-01T00:41:01.324+05:30', - type: 'identify', - }, - metadata: { - jobId: 1, - }, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - updateLastRequestAt: false, - collectContext: false, - }, - }, - }, - { - message: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - channel: 'mobile', - context: { - app: { - build: '1.0', - name: 'Test_Example', - namespace: 'com.example.testapp', - version: '1.0', - }, - device: { - id: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - manufacturer: 'Apple', - model: 'iPhone', - name: 'iPod touch (7th generation)', - type: 'iOS', - }, - library: { - name: 'test-ios-library', - version: '1.0.7', - }, - locale: 'en-US', - network: { - bluetooth: false, - carrier: 'unavailable', - cellular: false, - wifi: true, - }, - os: { - name: 'iOS', - version: '14.0', - }, - screen: { - density: 2, - height: 320, - width: 568, - }, - timezone: 'Asia/Kolkata', - traits: { - anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', - firstName: 'Test', - lastName: 'Name', - createdAt: '2020-09-30T19:11:00.337Z', - email: 'test_1@test.com', - phone: '9876543210', - key1: 'value1', - }, - userAgent: 'unknown', - }, - event: 'Test Event 2', - integrations: { - All: true, - }, - messageId: '1601493060-39010c49-e6e4-4626-a75c-0dbf1925c9e8', - originalTimestamp: '2020-09-30T19:11:00.337Z', - receivedAt: '2020-10-01T00:41:11.369+05:30', - request_ip: '2405:201:8005:9856:7911:25e7:5603:5e18', - sentAt: '2020-09-30T19:11:10.382Z', - timestamp: '2020-10-01T00:41:01.324+05:30', - type: 'identify', - }, - metadata: { - jobId: 2, - }, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - updateLastRequestAt: false, - collectContext: false, - }, - }, - }, - { - message: { - userId: 'user@5', - groupId: 'rudderlabs', - channel: 'web', - context: { - traits: { - email: 'test+5@rudderlabs.com', - phone: '+91 9599999999', - firstName: 'John', - lastName: 'Snow', - ownerId: '17', - }, - }, - traits: { - name: 'RudderStack', - size: 500, - website: 'www.rudderstack.com', - industry: 'CDP', - plan: 'enterprise', - }, - type: 'group', - originalTimestamp: '2023-11-10T14:42:44.724Z', - timestamp: '2023-11-22T10:12:44.757+05:30', - }, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - sendAnonymousId: false, - collectContext: false, - }, - }, - metadata: { - jobId: 3, - }, - }, - ], - destType: 'intercom', - }, + body: routerRequest3, }, }, output: { @@ -1124,22 +990,10 @@ export const data = [ files: {}, userId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', }, - metadata: [ - { - jobId: 1, - }, - ], + metadata: [generateMetadata(1)], batched: false, statusCode: 200, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - updateLastRequestAt: false, - }, - }, + destination: destination4, }, { batchedRequest: { @@ -1174,22 +1028,10 @@ export const data = [ files: {}, userId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', }, - metadata: [ - { - jobId: 2, - }, - ], + metadata: [generateMetadata(2)], batched: false, statusCode: 200, - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - updateLastRequestAt: false, - }, - }, + destination: destination4, }, { batched: false, @@ -1251,20 +1093,9 @@ export const data = [ version: '1', }, ], - destination: { - Config: { - apiKey: 'testApiKey', - apiVersion: 'v1', - collectContext: false, - sendAnonymousId: false, - }, - }, - metadata: [ - { - jobId: 3, - }, - ], - statusCode: 200, + destination: destination5, + metadata: [generateMetadata(3)], + statusCode: 299, }, ], }, From fa907cefc70ae0e8c3475e653bc7cf551d59e140 Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 17 Jun 2024 20:00:13 +0530 Subject: [PATCH 7/7] fix: some minor changes in tests --- .../destinations/intercom/router/data.ts | 70 +++++++++++++++---- 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/test/integrations/destinations/intercom/router/data.ts b/test/integrations/destinations/intercom/router/data.ts index 0d3cb4eb96..f0e6b46f4a 100644 --- a/test/integrations/destinations/intercom/router/data.ts +++ b/test/integrations/destinations/intercom/router/data.ts @@ -115,6 +115,47 @@ const destination5: Destination = { Transformations: [], }; +const destination6: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: {}, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v1', + sendAnonymousId: false, + updateLastRequestAt: false, + collectContext: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + +const destination7: Destination = { + ID: '123', + Name: 'intercom', + DestinationDefinition: { + ID: '123', + Name: 'intercom', + DisplayName: 'Intercom', + Config: {}, + }, + Config: { + apiKey: 'testApiKey', + apiVersion: 'v1', + sendAnonymousId: false, + collectContext: false, + }, + Enabled: true, + WorkspaceID: '123', + Transformations: [], +}; + const routerRequest1: RouterTransformationRequest = { input: [ { @@ -432,7 +473,7 @@ const routerRequest2: RouterTransformationRequest = { const routerRequest3: RouterTransformationRequest = { input: [ { - destination: destination4, + destination: destination6, message: { anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', channel: 'mobile', @@ -499,7 +540,7 @@ const routerRequest3: RouterTransformationRequest = { metadata: generateMetadata(1), }, { - destination: destination4, + destination: destination6, message: { anonymousId: '58b21c2d-f8d5-4410-a2d0-b268a26b7e33', channel: 'mobile', @@ -564,7 +605,7 @@ const routerRequest3: RouterTransformationRequest = { metadata: generateMetadata(2), }, { - destination: destination5, + destination: destination7, message: { userId: 'user@5', groupId: 'rudderlabs', @@ -599,9 +640,10 @@ export const data: RouterTestData[] = [ { id: 'Intercom-router-test-1', scenario: 'Framework', - successCriteria: 'Some events should be transformed successfully and some should fail', + successCriteria: + 'Some events should be transformed successfully and some should fail for apiVersion v2', name: 'intercom', - description: 'Intercom router tests 1', + description: 'Intercom router tests for apiVersion v2', feature: 'router', module: 'destination', version: 'v0', @@ -775,9 +817,10 @@ export const data: RouterTestData[] = [ { id: 'Intercom-router-test-2', scenario: 'Framework', - successCriteria: 'Some events should be transformed successfully and some should fail', + successCriteria: + 'Events should be transformed successfully for apiVersion v1 and cdk v2 enabled', name: 'intercom', - description: 'Intercom router tests 2', + description: 'Intercom router tests for apiVersion v1 and cdk v2 enabled', feature: 'router', module: 'destination', version: 'v0', @@ -940,9 +983,10 @@ export const data: RouterTestData[] = [ { id: 'Intercom-router-test-3', scenario: 'Framework', - successCriteria: 'Some events should be transformed successfully and some should fail', + successCriteria: + 'Events should be transformed successfully for apiVersion v1 and cdk v2 not enabled', name: 'intercom', - description: 'Intercom router tests 3', + description: 'Intercom router tests for apiVersion v1 and cdk v2 not enabled', feature: 'router', module: 'destination', version: 'v0', @@ -993,7 +1037,7 @@ export const data: RouterTestData[] = [ metadata: [generateMetadata(1)], batched: false, statusCode: 200, - destination: destination4, + destination: destination6, }, { batchedRequest: { @@ -1031,7 +1075,7 @@ export const data: RouterTestData[] = [ metadata: [generateMetadata(2)], batched: false, statusCode: 200, - destination: destination4, + destination: destination6, }, { batched: false, @@ -1093,9 +1137,9 @@ export const data: RouterTestData[] = [ version: '1', }, ], - destination: destination5, + destination: destination7, metadata: [generateMetadata(3)], - statusCode: 299, + statusCode: 200, }, ], },