From b179787b653beec9656ffccb71499f9f484fdacc Mon Sep 17 00:00:00 2001 From: Sai Sankeerth Date: Wed, 20 Sep 2023 18:41:30 +0530 Subject: [PATCH] feat: add axios mocking to component test-suite Signed-off-by: Sai Sankeerth --- package-lock.json | 12 + package.json | 2 + src/adapters/network.js | 1 + test/integrations/component.test.ts | 79 +- .../destinations/pardot/router/data.ts | 985 ++++++++++++++++++ test/integrations/testTypes.ts | 7 + test/integrations/testUtils.ts | 6 +- 7 files changed, 1088 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1bd460d2ab..a729e2a098 100644 --- a/package-lock.json +++ b/package-lock.json @@ -72,6 +72,7 @@ "devDependencies": { "@commitlint/config-conventional": "^17.6.3", "@digitalroute/cz-conventional-changelog-for-jira": "^8.0.1", + "@types/fast-json-stable-stringify": "^2.1.0", "@types/jest": "^29.5.1", "@types/koa": "^2.13.6", "@types/koa-bodyparser": "^4.3.10", @@ -92,6 +93,7 @@ "eslint-plugin-json": "^3.1.0", "eslint-plugin-sonarjs": "^0.19.0", "eslint-plugin-unicorn": "^46.0.1", + "fast-json-stable-stringify": "^2.1.0", "glob": "^10.3.3", "http-terminator": "^3.2.0", "husky": "^8.0.3", @@ -4595,6 +4597,16 @@ "@types/send": "*" } }, + "node_modules/@types/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@types/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-IyNhGHu71jH1jCXTHmafuoAAdsbBON3kDh7u/UUhLmjYgN5TYB54e1R8ckTCiIevl2UuZaCsi9XRxineY5yUjw==", + "deprecated": "This is a stub types definition. fast-json-stable-stringify provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "fast-json-stable-stringify": "*" + } + }, "node_modules/@types/graceful-fs": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz", diff --git a/package.json b/package.json index 1dd7f5e2fc..0403e600f0 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,7 @@ "devDependencies": { "@commitlint/config-conventional": "^17.6.3", "@digitalroute/cz-conventional-changelog-for-jira": "^8.0.1", + "@types/fast-json-stable-stringify": "^2.1.0", "@types/jest": "^29.5.1", "@types/koa": "^2.13.6", "@types/koa-bodyparser": "^4.3.10", @@ -133,6 +134,7 @@ "eslint-plugin-json": "^3.1.0", "eslint-plugin-sonarjs": "^0.19.0", "eslint-plugin-unicorn": "^46.0.1", + "fast-json-stable-stringify": "^2.1.0", "glob": "^10.3.3", "http-terminator": "^3.2.0", "husky": "^8.0.3", diff --git a/src/adapters/network.js b/src/adapters/network.js index 78552048f0..d08123d1b6 100644 --- a/src/adapters/network.js +++ b/src/adapters/network.js @@ -388,4 +388,5 @@ module.exports = { getPayloadData, getFormData, handleHttpRequest, + enhanceRequestOptions }; diff --git a/test/integrations/component.test.ts b/test/integrations/component.test.ts index 374649dfad..a23a9dbce3 100644 --- a/test/integrations/component.test.ts +++ b/test/integrations/component.test.ts @@ -1,12 +1,16 @@ import { join } from 'path'; import Koa from 'koa'; import request from 'supertest'; +// Mocking of axios calls +import axios from 'axios'; +// new-library we are using +import stringify from 'fast-json-stable-stringify'; import bodyParser from 'koa-bodyparser'; import { Command } from 'commander'; import { createHttpTerminator } from 'http-terminator'; -import { TestCaseData } from './testTypes'; +import { MockHttpCallsData, TestCaseData } from './testTypes'; import { applicationRoutes } from '../../src/routes/index'; -import { getTestDataFilePaths, getTestData } from './testUtils'; +import { getTestDataFilePaths, getTestData, getMockHttpCallsData } from './testUtils'; import tags from '../../src/v0/util/tags'; import { Server } from 'http'; @@ -34,6 +38,68 @@ afterAll(async () => { await createHttpTerminator({ server }).terminate(); }); +// unmock already existing axios-mocking +jest.unmock('axios') + +jest.mock('axios') +const formAxiosReqsMap = (calls: MockHttpCallsData[]) => { + try { + return calls.reduce((agg, curr) => { + let obj = curr.httpReq; + return { ...agg, [stringify(obj)]: curr.httpRes }; + }, {}) + } catch (error) { + return {} + } +} + +const mockImpl = (type, axReqMap) => { + // return value fn + const retVal = (key) => { + if (axReqMap[key]) { + return axReqMap[key]; + } + return { + status: 500, + body: 'Something bad' + } + } + + if (['constructor'].includes(type)) { + return (opts) => { + // mock result from some cache + const key = stringify({ ...opts }) + return retVal(key); + }; + } else if (['delete', 'get'].includes(type)) { + return (url, opts) => { + // mock result from some cache + const key = stringify({ url, ...opts}) + return retVal(key); + }; + } + + // post, patch, put + return (url, data, opts) => { + // mock result from some cache + const key = stringify({ url, data, ...opts }) + return retVal(key); + }; +}; + +const makeNetworkMocks = (axiosReqsMap: Record) => { + axios.put = jest.fn(mockImpl('put', axiosReqsMap)) + axios.post = jest.fn(mockImpl('post', axiosReqsMap)) + axios.patch = jest.fn(mockImpl('patch', axiosReqsMap)) + // @ts-ignore + axios.delete = jest.fn(mockImpl('delete', axiosReqsMap)) + // @ts-ignore + axios.get = jest.fn(mockImpl('get', axiosReqsMap)) + // @ts-ignore + axios.mockImplementation(mockImpl('constructor', axiosReqsMap)) +} + +// END const rootDir = __dirname; const allTestDataFilePaths = getTestDataFilePaths(rootDir, opts.destination); const DEFAULT_VERSION = 'v0'; @@ -65,7 +131,7 @@ const testRoute = async (route, tcData: TestCaseData) => { const outputResp = tcData.output.response || ({} as any); expect(response.status).toEqual(outputResp.status); - if (outputResp && outputResp.body) { + if (outputResp?.body) { expect(response.body).toEqual(outputResp.body); } @@ -111,6 +177,13 @@ const sourceTestHandler = async (tcData) => { )}`; await testRoute(route, tcData); }; +// all the axios requests will be stored in this map +const allAxiosReqsMap = allTestDataFilePaths.reduce((agg, currPath) => { + const mockNetworkCallsData: MockHttpCallsData[] = getMockHttpCallsData(currPath); + const reqMap = formAxiosReqsMap(mockNetworkCallsData) + return {...agg, ...reqMap} +}, {}) +makeNetworkMocks(allAxiosReqsMap); // Trigger the test suites describe.each(allTestDataFilePaths)('%s Tests', (testDataPath) => { diff --git a/test/integrations/destinations/pardot/router/data.ts b/test/integrations/destinations/pardot/router/data.ts index 28680deafc..c8cd23528e 100644 --- a/test/integrations/destinations/pardot/router/data.ts +++ b/test/integrations/destinations/pardot/router/data.ts @@ -1,3 +1,6 @@ +import { enhanceRequestOptions, getFormData } from "../../../../../src/adapters/network"; +import { FEATURES, MODULES } from "../../../../../src/v0/util/tags"; + export const data = [ { name: 'pardot', @@ -1014,4 +1017,986 @@ export const data = [ }, }, }, + { + name: 'pardot', + description: 'Test proxy - 0', + feature: FEATURES.DATA_DELIVERY, + module: MODULES.DESTINATION, + version: 'v0', + input: { + request: { + body:{ + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://pi.pardot.com/api/prospect/version/4/do/upsert/id/123435", + "headers": { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ" + }, + "body": { + "JSON": {}, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": { + "first_name": "Roger12", + "last_name": "Federer12", + "website": "https://rudderstack.com", + "score": 14, + "campaign_id": 42213 + } + }, + "files": {}, + "params": { + "destination": "pardot" + } + }, + method: 'POST' + } + }, + output: { + response: { + status: 200, + body: { + "output": { + "message": "Request Processed Successfully", + "status": 200, + "destinationResponse": { + "response": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger12", + "last_name": "Federer12", + "email": "Roger12@waltair.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": null, + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": null, + "crm_last_sync": null, + "crm_url": null, + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 200 + } + } + } + } + } + }, + { + name: 'pardot', + description: 'Test proxy - 1', + feature: FEATURES.DATA_DELIVERY, + module: MODULES.DESTINATION, + version: 'v0', + input: { + request: { + body:{ + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://pi.pardot.com/api/prospect/version/4/do/upsert/email/Roger_12@waltair.io", + "headers": { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ" + }, + "body": { + "JSON": {}, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": { + "first_name": "Roger_12", + "last_name": "Federer_12", + "website": "https://rudderstack.com", + "score": 14, + "campaign_id": 42213 + } + }, + "files": {}, + "params": { + "destination": "pardot" + } + }, + method: 'POST' + } + }, + output: { + response: { + status: 200, + body: { + "output": { + "message": "Request Processed Successfully", + "status": 201, + "destinationResponse": { + "response": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger_12", + "last_name": "Federer_12", + "email": "Roger_12@waltair.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": null, + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": null, + "crm_last_sync": null, + "crm_url": null, + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 201 + } + } + } + } + } + }, + { + name: 'pardot', + description: 'Test proxy - 2', + feature: FEATURES.DATA_DELIVERY, + module: MODULES.DESTINATION, + version: 'v0', + input: { + request: { + body: { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://pi.pardot.com/api/prospect/version/4/do/upsert/fid/00Q6r000002LKhTPVR", + "headers": { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ" + }, + "body": { + "JSON": {}, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": { + "first_name": "Nick", + "last_name": "Kyrgios", + "website": "https://rudderstack.com", + "score": 12, + "campaign_id": 42213 + } + }, + "files": {}, + "params": { + "destination": "pardot" + } + }, + method: 'POST' + } + }, + output: { + response: { + status: 200, + body: { + "output": { + "message": "Request Processed Successfully", + "status": 200, + "destinationResponse": { + "response": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger_12", + "last_name": "Federer_12", + "email": "Roger_12@federer.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": "00Q6r000002LKhTPVR", + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": "00Q6r000002LKhTPVR", + "crm_last_sync": "2022-01-21 18:47:37", + "crm_url": "https://testcompany.my.salesforce.com/00Q6r000002LKhTPVR", + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 200 + } + } + } + } + } + }, + { + name: 'pardot', + description: 'Test proxy - 3', + feature: FEATURES.DATA_DELIVERY, + module: MODULES.DESTINATION, + version: 'v0', + input: { + request: { + body: { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://pi.pardot.com/api/prospect/version/4/do/upsert/email/rolex_waltair@mywebsite.io", + "headers": { + "Authorization": "Bearer myExpiredToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ" + }, + "body": { + "JSON": {}, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": { + "first_name": "Rolex", + "last_name": "Waltair", + "website": "https://rudderstack.com", + "score": 15, + "campaign_id": 42213 + } + }, + "files": {}, + "params": { + "destination": "pardot" + } + }, + method: 'POST' + } + }, + output: { + response: { + status: 500, + body: { + "output": { + "message": "access_token is invalid, unknown, or malformed: Inactive token during Pardot response transformation", + "status": 500, + "authErrorCategory": "REFRESH_TOKEN", + "destinationResponse": { + "@attributes": { + "stat": "fail", + "version": 1, + "err_code": 184 + }, + "err": "access_token is invalid, unknown, or malformed: Inactive token" + }, + "statTags": { + "destType": "PARDOT", + "errorCategory": "network", + "destinationId": "Non-determininable", + "workspaceId": "Non-determininable", + "errorType": "retryable", + "feature": "dataDelivery", + "implementation": "native", + "module": "destination" + } + } + } + } + } + }, ]; + +export const networkCallsData = [ + // 2nd proxy test-case + { + httpReq: enhanceRequestOptions({ + url: "https://pi.pardot.com/api/prospect/version/4/do/upsert/email/Roger_12@waltair.io", + data: getFormData({ + "first_name": "Roger_12", + "last_name": "Federer_12", + "website": "https://rudderstack.com", + "score": 14, + "campaign_id": 42213 + }), + params: { destination: "pardot" }, + headers: { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ", + 'User-Agent': "RudderLabs" + }, + method: "POST", + }), + httpRes: { + "data": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger_12", + "last_name": "Federer_12", + "email": "Roger_12@waltair.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": null, + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": null, + "crm_last_sync": null, + "crm_url": null, + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 201, + "statusText": "Created" + } + }, + // 4th proxy test-case + { + httpReq: enhanceRequestOptions({ + url: "https://pi.pardot.com/api/prospect/version/4/do/upsert/email/rolex_waltair@mywebsite.io", + data: getFormData({ + "first_name": "Rolex", + "last_name": "Waltair", + "website": "https://rudderstack.com", + "score": 15, + "campaign_id": 42213, + "format": "json" + }), + params: { destination: "pardot" }, + headers: { + "Authorization": "Bearer myExpiredToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ", + 'User-Agent': "RudderLabs" + }, + method: "POST", + }), + httpRes: { + "data": { + "@attributes": { + "stat": "fail", + "version": 1, + "err_code": 184 + }, + "err": "access_token is invalid, unknown, or malformed: Inactive token" + }, + "status": 401, + "statusText": "Unauthorized" + } + }, + // 1st proxy test-case + { + httpReq: enhanceRequestOptions({ + url: "https://pi.pardot.com/api/prospect/version/4/do/upsert/id/123435", + data: getFormData({ + "first_name": "Roger12", + "last_name": "Federer12", + "website": "https://rudderstack.com", + "score": 14, + "campaign_id": 42213, + "format": "json" + }), + params: { destination: "pardot" }, + headers: { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ", + 'User-Agent': "RudderLabs" + }, + method: "POST", + }), + httpRes: { + "data": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger12", + "last_name": "Federer12", + "email": "Roger12@waltair.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": null, + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": null, + "crm_last_sync": null, + "crm_url": null, + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 200, + "statusText": "OK" + } + }, + // 3rd proxy test-case + { + httpReq: enhanceRequestOptions({ + url: "https://pi.pardot.com/api/prospect/version/4/do/upsert/fid/00Q6r000002LKhTPVR", + data: getFormData({ + "first_name": "Nick", + "last_name": "Kyrgios", + "website": "https://rudderstack.com", + "score": 12, + "campaign_id": 42213, + "format": "json" + }), + params: { destination: "pardot" }, + headers: { + "Authorization": "Bearer myToken", + "Pardot-Business-Unit-Id": "0Uv2v000000k9tHCAQ", + 'User-Agent': "RudderLabs" + }, + method: "POST", + }), + httpRes: { + "data": { + "@attributes": { + "stat": "ok", + "version": 1 + }, + "prospect": { + "id": 123435, + "campaign_id": 42213, + "salutation": null, + "first_name": "Roger_12", + "last_name": "Federer_12", + "email": "Roger_12@federer.io", + "password": null, + "company": null, + "website": "https://rudderstack.com", + "job_title": null, + "department": null, + "country": "AU", + "address_one": null, + "address_two": null, + "city": null, + "state": null, + "territory": null, + "zip": null, + "phone": null, + "fax": null, + "source": null, + "annual_revenue": null, + "employees": null, + "industry": null, + "years_in_business": null, + "comments": null, + "notes": null, + "score": 14, + "grade": null, + "last_activity_at": null, + "recent_interaction": "Never active.", + "crm_lead_fid": "00Q6r000002LKhTPVR", + "crm_contact_fid": null, + "crm_owner_fid": "00G2v000004WYXaEAO", + "crm_account_fid": null, + "salesforce_fid": "00Q6r000002LKhTPVR", + "crm_last_sync": "2022-01-21 18:47:37", + "crm_url": "https://testcompany.my.salesforce.com/00Q6r000002LKhTPVR", + "is_do_not_email": null, + "is_do_not_call": null, + "opted_out": null, + "is_reviewed": 1, + "is_starred": null, + "created_at": "2022-01-21 18:21:46", + "updated_at": "2022-01-21 18:48:41", + "campaign": { + "id": 42113, + "name": "Test", + "crm_fid": "7012y000000MNOCLL4" + }, + "assigned_to": { + "user": { + "id": 38443703, + "email": "test_rudderstack@testcompany.com", + "first_name": "Rudderstack", + "last_name": "User", + "job_title": null, + "role": "Administrator", + "account": 489853, + "created_at": "2021-02-26 06:25:17", + "updated_at": "2021-02-26 06:25:17" + } + }, + "Are_you_shipping_large_fragile_or_bulky_items": false, + "Calendly": false, + "Country_Code": "AU", + "Currency": "AUD", + "Inventory_or_Warehouse_Management_System": false, + "Lead_Status": "New", + "Marketing_Stage": "SAL", + "Record_Type_ID": "TestCompany Lead", + "profile": { + "id": 304, + "name": "Default", + "profile_criteria": [ + { + "id": 1500, + "name": "Shipping Volume", + "matches": "Unknown" + }, + { + "id": 1502, + "name": "Industry", + "matches": "Unknown" + }, + { + "id": 1506, + "name": "Job Title", + "matches": "Unknown" + }, + { + "id": 1508, + "name": "Department", + "matches": "Unknown" + } + ] + }, + "visitors": null, + "visitor_activities": null, + "lists": null + } + }, + "status": 200, + "statusText": "OK" + } + }, +] \ No newline at end of file diff --git a/test/integrations/testTypes.ts b/test/integrations/testTypes.ts index 57d9c812e9..6b90ba9c13 100644 --- a/test/integrations/testTypes.ts +++ b/test/integrations/testTypes.ts @@ -1,3 +1,5 @@ +import { AxiosResponse } from "axios"; + export interface requestType { method: string; body?: any; @@ -35,3 +37,8 @@ export interface TestCaseData { output: outputType; mock?: mockType[]; } + +export type MockHttpCallsData = { + httpReq: Record; + httpRes: Partial; +} \ No newline at end of file diff --git a/test/integrations/testUtils.ts b/test/integrations/testUtils.ts index 815b211d20..df56d3cfea 100644 --- a/test/integrations/testUtils.ts +++ b/test/integrations/testUtils.ts @@ -1,6 +1,6 @@ import { globSync } from 'glob'; import { join } from 'path'; -import { TestCaseData } from './testTypes'; +import { MockHttpCallsData, TestCaseData } from './testTypes'; export const getTestDataFilePaths = (dirPath: string, destination: string = ''): string[] => { const globPattern = join(dirPath, '**', 'data.ts'); @@ -14,3 +14,7 @@ export const getTestDataFilePaths = (dirPath: string, destination: string = ''): export const getTestData = (filePath): TestCaseData[] => { return require(filePath).data as TestCaseData[]; }; + +export const getMockHttpCallsData = (filePath): MockHttpCallsData[] => { + return require(filePath).networkCallsData as MockHttpCallsData[]; +};