From a6f8725973c04e8cd0c1308d8483d8240b9b36ed Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Fri, 9 Feb 2024 11:21:40 +0530 Subject: [PATCH 1/9] chore: add initial business tests --- .../salesforce/dataDelivery/business.ts | 720 ++++++++++++++++++ .../salesforce/dataDelivery/data.ts | 76 +- .../salesforce/dataDelivery/other.ts | 0 .../destinations/salesforce/network.ts | 243 ++++-- 4 files changed, 922 insertions(+), 117 deletions(-) create mode 100644 test/integrations/destinations/salesforce/dataDelivery/business.ts create mode 100644 test/integrations/destinations/salesforce/dataDelivery/other.ts diff --git a/test/integrations/destinations/salesforce/dataDelivery/business.ts b/test/integrations/destinations/salesforce/dataDelivery/business.ts new file mode 100644 index 0000000000..31c999e119 --- /dev/null +++ b/test/integrations/destinations/salesforce/dataDelivery/business.ts @@ -0,0 +1,720 @@ +import { ProxyMetdata } from '../../../../../src/types'; +import { generateProxyV1Payload } from '../../../testUtils'; + +const commonHeaders = { + Authorization: 'Bearer token', + 'Content-Type': 'application/json', +}; +const params = { destination: 'salesforce' }; + +const users = [ + { + Email: 'danis.archurav@sbermarket.ru', + Company: 'itus.ru', + LastName: 'Danis', + FirstName: 'Archurav', + LeadSource: 'App Signup', + account_type__c: 'free_trial', + }, +]; + +const proxyMetdata: ProxyMetdata = { + jobId: 1, + attemptNum: 1, + userId: 'dummyUserId', + sourceId: 'dummySourceId', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + secret: {}, + dontBatch: false, +}; + +const reqMetadataArray = [proxyMetdata]; + +const commonRequestParameters = { + headers: commonHeaders, + JSON: users[0], + params, +}; + +const externalIdSearchData = { Planning_Categories__c: 'pc', External_ID__c: 123 }; +const externalIDSearchedData = { + headers: commonHeaders, + JSON: externalIdSearchData, + params, +}; + +console.log( + JSON.stringify( + generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/invalid_session_id', + }, + reqMetadataArray, + ), + ), +); + +export const testScenariosForV1API = [ + { + id: 'salesforce_v1_scenario_1', + name: 'salesforce', + description: 'Lead creation with existing unchanged leadId and unchanged data', + successCriteria: 'Should return 200 with no error with destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/existing_unchanged_leadId', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + status: 200, + message: 'Request for destination: salesforce Processed Successfully', + response: [ + { + error: '{"statusText":"No Content"}', + metadata: proxyMetdata, + statusCode: 200, + }, + ], + }, + }, + }, + }, + }, + { + id: 'salesforce_v1_scenario_2', + name: 'salesforce', + description: 'salesforce', + successCriteria: 'Should return 5XX with error Session expired or invalid, INVALID_SESSION_ID', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/invalid_session_id', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + status: 500, + message: + 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', + response: [ + { + error: + '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', + metadata: proxyMetdata, + statusCode: 500, + }, + ], + statTags: { + destType: 'SALESFORCE', + errorCategory: 'network', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + errorType: 'retryable', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + }, + }, + }, + }, + }, + }, + { + id: 'salesforce_v1_scenario_3', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + status: 400, + message: + 'Salesforce Request Failed: "401" due to "INVALID_HEADER_TYPE", (Aborted) during Salesforce Response Handling', + response: [ + { + error: '[{"message":"INVALID_HEADER_TYPE","errorCode":"INVALID_AUTH_HEADER"}]', + metadata: proxyMetdata, + statusCode: 400, + }, + ], + statTags: { + destType: 'SALESFORCE', + errorCategory: 'network', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + errorType: 'aborted', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + }, + }, + }, + }, + }, + }, + + { + id: 'salesforce_v1_scenario_4', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: + 'Salesforce Request Failed - due to "REQUEST_LIMIT_EXCEEDED", (Throttled) during Salesforce Response Handling', + response: [ + { + error: + '[{"message":"Request limit exceeded","errorCode":"REQUEST_LIMIT_EXCEEDED"}]', + metadata: { + attemptNum: 1, + destinationId: 'dummyDestinationId', + dontBatch: false, + jobId: 1, + secret: {}, + sourceId: 'dummySourceId', + userId: 'dummyUserId', + workspaceId: 'dummyWorkspaceId', + }, + statusCode: 429, + }, + ], + statTags: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'throttled', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + status: 429, + }, + }, + }, + }, + }, + + { + id: 'salesforce_v1_scenario_5', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/5', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: + 'Salesforce Request Failed - due to "Server Unavailable", (Retryable) during Salesforce Response Handling', + response: [ + { + error: '[{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}]', + metadata: { + attemptNum: 1, + destinationId: 'dummyDestinationId', + dontBatch: false, + jobId: 1, + secret: {}, + sourceId: 'dummySourceId', + userId: 'dummyUserId', + workspaceId: 'dummyWorkspaceId', + }, + statusCode: 500, + }, + ], + statTags: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'retryable', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + status: 500, + }, + }, + }, + }, + }, + + { + id: 'salesforce_v1_scenario_6', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/6', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: + 'Salesforce Request Failed: "400" due to "{"error":"invalid_grant","error_description":"authentication failure"}", (Aborted) during Salesforce Response Handling', + response: [ + { + error: '{"error":"invalid_grant","error_description":"authentication failure"}', + metadata: { + attemptNum: 1, + destinationId: 'dummyDestinationId', + dontBatch: false, + jobId: 1, + secret: {}, + sourceId: 'dummySourceId', + userId: 'dummyUserId', + workspaceId: 'dummyWorkspaceId', + }, + statusCode: 400, + }, + ], + statTags: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'aborted', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + status: 400, + }, + }, + }, + }, + }, + + { + id: 'salesforce_v1_scenario_7', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/7', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: + 'Salesforce Request Failed - due to "{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}", (Retryable) during Salesforce Response Handling', + response: [ + { + error: '{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}', + metadata: { + attemptNum: 1, + destinationId: 'dummyDestinationId', + dontBatch: false, + jobId: 1, + secret: {}, + sourceId: 'dummySourceId', + userId: 'dummyUserId', + workspaceId: 'dummyWorkspaceId', + }, + statusCode: 500, + }, + ], + statTags: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'retryable', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + status: 500, + }, + }, + }, + }, + }, + + { + id: 'salesforce_v1_scenario_8', + name: 'salesforce', + description: 'salesforce', + successCriteria: '', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...externalIDSearchedData, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: 'Request for destination: salesforce Processed Successfully', + response: [ + { + error: + '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', + metadata: { + attemptNum: 1, + destinationId: 'dummyDestinationId', + dontBatch: false, + jobId: 1, + secret: {}, + sourceId: 'dummySourceId', + userId: 'dummyUserId', + workspaceId: 'dummyWorkspaceId', + }, + statusCode: 200, + }, + ], + status: 200, + }, + }, + }, + }, + }, + + // { + // id: 'salesforce_v1_scenario_4', + // name: 'salesforce', + // description: 'salesforce', + // successCriteria: '', + // scenario: 'Business', + // feature: 'dataDelivery', + // module: 'destination', + // version: 'v1', + // input: { + // request: { + // body: generateProxyV1Payload( + // { + // ...commonRequestParameters, + // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', + // }, + // reqMetadataArray, + // ), + // method: 'POST', + // }, + // }, + // output: { + // response: { + // status: 200, + // body: {}, + // }, + // }, + // }, + + // { + // id: 'salesforce_v1_scenario_4', + // name: 'salesforce', + // description: 'salesforce', + // successCriteria: '', + // scenario: 'Business', + // feature: 'dataDelivery', + // module: 'destination', + // version: 'v1', + // input: { + // request: { + // body: generateProxyV1Payload( + // { + // ...commonRequestParameters, + // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', + // }, + // reqMetadataArray, + // ), + // method: 'POST', + // }, + // }, + // output: { + // response: { + // status: 200, + // body: {}, + // }, + // }, + // }, + + // { + // id: 'salesforce_v1_scenario_3', + // name: 'salesforce', + // description: 'salesforce', + // successCriteria: '', + // scenario: 'Business', + // feature: 'dataDelivery', + // module: 'destination', + // version: 'v1', + // input: { + // request: { + // body: generateProxyV1Payload( + // { + // ...commonRequestParameters, + // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', + // }, + // reqMetadataArray, + // ), + // method: 'POST', + // }, + // }, + // output: { + // response: { + // status: 200, + // body: { + // output: { + // status: 500, + // message: + // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', + // response: [ + // { + // error: + // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', + // metadata: proxyMetdata, + // statusCode: 500, + // }, + // ], + // statTags: { + // destType: 'SALESFORCE', + // errorCategory: 'network', + // destinationId: 'dummyDestinationId', + // workspaceId: 'dummyWorkspaceId', + // errorType: 'retryable', + // feature: 'dataDelivery', + // implementation: 'native', + // module: 'destination', + // }, + // }, + // }, + // }, + // }, + // }, + + // { + // id: 'salesforce_v1_scenario_3', + // name: 'salesforce', + // description: 'salesforce', + // successCriteria: '', + // scenario: 'Business', + // feature: 'dataDelivery', + // module: 'destination', + // version: 'v1', + // input: { + // request: { + // body: generateProxyV1Payload( + // { + // ...commonRequestParameters, + // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', + // }, + // reqMetadataArray, + // ), + // method: 'POST', + // }, + // }, + // output: { + // response: { + // status: 200, + // body: { + // output: { + // status: 500, + // message: + // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', + // response: [ + // { + // error: + // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', + // metadata: proxyMetdata, + // statusCode: 500, + // }, + // ], + // statTags: { + // destType: 'SALESFORCE', + // errorCategory: 'network', + // destinationId: 'dummyDestinationId', + // workspaceId: 'dummyWorkspaceId', + // errorType: 'retryable', + // feature: 'dataDelivery', + // implementation: 'native', + // module: 'destination', + // }, + // }, + // }, + // }, + // }, + // }, + + // { + // id: 'salesforce_v1_scenario_3', + // name: 'salesforce', + // description: 'salesforce', + // successCriteria: '', + // scenario: 'Business', + // feature: 'dataDelivery', + // module: 'destination', + // version: 'v1', + // input: { + // request: { + // body: generateProxyV1Payload( + // { + // ...commonRequestParameters, + // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', + // }, + // reqMetadataArray, + // ), + // method: 'POST', + // }, + // }, + // output: { + // response: { + // status: 200, + // body: { + // output: { + // status: 500, + // message: + // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', + // response: [ + // { + // error: + // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', + // metadata: proxyMetdata, + // statusCode: 500, + // }, + // ], + // statTags: { + // destType: 'SALESFORCE', + // errorCategory: 'network', + // destinationId: 'dummyDestinationId', + // workspaceId: 'dummyWorkspaceId', + // errorType: 'retryable', + // feature: 'dataDelivery', + // implementation: 'native', + // module: 'destination', + // }, + // }, + // }, + // }, + // }, + // }, +]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/data.ts b/test/integrations/destinations/salesforce/dataDelivery/data.ts index cfaa75e23e..6aaa48b05f 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/data.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/data.ts @@ -1,7 +1,17 @@ import { AxiosError } from 'axios'; import MockAdapter from 'axios-mock-adapter'; +import { testScenariosForV1API } from './business'; -export const data = [ +const legacyDataValue = { + Email: 'danis.archurav@sbermarket.ru', + Company: 'itus.ru', + LastName: 'Danis', + FirstName: 'Archurav', + LeadSource: 'App Signup', + account_type__c: 'free_trial', +}; + +const legacyTests = [ { name: 'salesforce', description: 'Test 0', @@ -24,14 +34,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -86,14 +89,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -162,14 +158,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -238,14 +227,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -314,14 +296,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -390,14 +365,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -464,14 +432,7 @@ export const data = [ body: { XML: {}, FORM: {}, - JSON: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + JSON: legacyDataValue, JSON_ARRAY: {}, }, metadata: { @@ -781,3 +742,4 @@ export const data = [ }, }, ]; +export const data = [...legacyTests, ...testScenariosForV1API]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/other.ts b/test/integrations/destinations/salesforce/dataDelivery/other.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/integrations/destinations/salesforce/network.ts b/test/integrations/destinations/salesforce/network.ts index 396fad9d69..fc341366aa 100644 --- a/test/integrations/destinations/salesforce/network.ts +++ b/test/integrations/destinations/salesforce/network.ts @@ -1,15 +1,23 @@ +const commonHeaders = { + Authorization: 'Bearer token', + 'Content-Type': 'application/json', +}; + +const dataValue = { + Email: 'danis.archurav@sbermarket.ru', + Company: 'itus.ru', + LastName: 'Danis', + FirstName: 'Archurav', + LeadSource: 'App Signup', + account_type__c: 'free_trial', +}; + + const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/1', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', @@ -26,14 +34,7 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/3', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', @@ -50,19 +51,11 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', - Authorization: 'Bearer Incorrect_token', - 'User-Agent': 'RudderLabs', + Authorization: 'Bearer token', }, method: 'POST', }, @@ -74,14 +67,7 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', @@ -98,14 +84,7 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/5', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', @@ -122,14 +101,7 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/6', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', @@ -146,19 +118,11 @@ const tfProxyMocksData = [ { httpReq: { url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/7', - data: { - Email: 'denis.kornilov@sbermarket.ru', - Company: 'sbermarket.ru', - LastName: 'Корнилов', - FirstName: 'Денис', - LeadSource: 'App Signup', - account_type__c: 'free_trial', - }, + data: dataValue, params: { destination: 'salesforce' }, headers: { 'Content-Type': 'application/json', Authorization: 'Bearer token', - 'User-Agent': 'RudderLabs', }, method: 'POST', }, @@ -323,4 +287,163 @@ const transformationMocksData = [ }, }, ]; -export const networkCallsData = [...tfProxyMocksData, ...transformationMocksData]; + +const businessMockData = [ + { + description: + 'Mock response from destination depicting a valid lead request, with no changed data', + httpReq: { + method: 'post', + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/existing_unchanged_leadId', + data: dataValue, + headers: commonHeaders, + }, + httpRes: { + data: { statusText: 'No Content' }, + status: 204, + }, + }, + { + description: 'Mock response from destination depicting a invalid session id', + httpReq: { + method: 'post', + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/invalid_session_id', + data: dataValue, + headers: commonHeaders, + }, + httpRes: { + data: [{ message: 'Session expired or invalid', errorCode: 'INVALID_SESSION_ID' }], + status: 500, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', + data: dataValue, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer Incorrect_token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: [{ message: 'INVALID_HEADER_TYPE', errorCode: 'INVALID_AUTH_HEADER' }], + status: 401, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', + data: dataValue, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: [{ message: 'Request limit exceeded', errorCode: 'REQUEST_LIMIT_EXCEEDED' }], + status: 403, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/5', + data: dataValue, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: [{ message: 'Server Unavailable', errorCode: 'SERVER_UNAVAILABLE' }], + status: 503, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/6', + data: dataValue, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: { error: 'invalid_grant', error_description: 'authentication failure' }, + status: 400, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/7', + data: dataValue, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: { + message: 'Server Unavailable', + errorCode: 'SERVER_UNAVAILABLE', + }, + status: 503, + }, + }, + { + httpReq: { + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', + data: { Planning_Categories__c: 'pc', External_ID__c: 123 }, + params: { destination: 'salesforce' }, + headers: { + 'Content-Type': 'application/json', + Authorization: 'Bearer token', + 'User-Agent': 'RudderLabs', + }, + method: 'POST', + }, + httpRes: { + data: { + searchRecords: [ + { + attributes: { + type: 'object_name', + url: '/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA', + }, + Id: 'a0J75100002w97gEAA', + External_ID__c: 'external_id', + }, + { + attributes: { + type: 'object_name', + url: '/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI', + }, + Id: 'a0J75200002w9ZsEAI', + External_ID__c: 'external_id TEST', + }, + ], + }, + status: 200, + }, + }, +]; + +export const networkCallsData = [ + ...tfProxyMocksData, + ...transformationMocksData, + ...businessMockData, +]; From d5e8b3c712557ebc08786f3729714b3adb0c5fac Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:52:23 +0530 Subject: [PATCH 2/9] chore: cleanup --- .../salesforce/dataDelivery/business.ts | 384 ++---------------- 1 file changed, 44 insertions(+), 340 deletions(-) diff --git a/test/integrations/destinations/salesforce/dataDelivery/business.ts b/test/integrations/destinations/salesforce/dataDelivery/business.ts index 31c999e119..2379807c13 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/business.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/business.ts @@ -18,6 +18,39 @@ const users = [ }, ]; +const statTags = { + aborted: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'aborted', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + retryable: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'retryable', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, + throttled: { + destType: 'SALESFORCE', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'throttled', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, +}; + const proxyMetdata: ProxyMetdata = { jobId: 1, attemptNum: 1, @@ -44,19 +77,6 @@ const externalIDSearchedData = { params, }; -console.log( - JSON.stringify( - generateProxyV1Payload( - { - ...commonRequestParameters, - endpoint: - 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/invalid_session_id', - }, - reqMetadataArray, - ), - ), -); - export const testScenariosForV1API = [ { id: 'salesforce_v1_scenario_1', @@ -137,16 +157,7 @@ export const testScenariosForV1API = [ statusCode: 500, }, ], - statTags: { - destType: 'SALESFORCE', - errorCategory: 'network', - destinationId: 'dummyDestinationId', - workspaceId: 'dummyWorkspaceId', - errorType: 'retryable', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - }, + statTags: statTags.retryable, }, }, }, @@ -188,16 +199,7 @@ export const testScenariosForV1API = [ statusCode: 400, }, ], - statTags: { - destType: 'SALESFORCE', - errorCategory: 'network', - destinationId: 'dummyDestinationId', - workspaceId: 'dummyWorkspaceId', - errorType: 'aborted', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - }, + statTags: statTags.aborted, }, }, }, @@ -236,29 +238,11 @@ export const testScenariosForV1API = [ { error: '[{"message":"Request limit exceeded","errorCode":"REQUEST_LIMIT_EXCEEDED"}]', - metadata: { - attemptNum: 1, - destinationId: 'dummyDestinationId', - dontBatch: false, - jobId: 1, - secret: {}, - sourceId: 'dummySourceId', - userId: 'dummyUserId', - workspaceId: 'dummyWorkspaceId', - }, + metadata: proxyMetdata, statusCode: 429, }, ], - statTags: { - destType: 'SALESFORCE', - destinationId: 'dummyDestinationId', - errorCategory: 'network', - errorType: 'throttled', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - workspaceId: 'dummyWorkspaceId', - }, + statTags: statTags.throttled, status: 429, }, }, @@ -297,29 +281,11 @@ export const testScenariosForV1API = [ response: [ { error: '[{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}]', - metadata: { - attemptNum: 1, - destinationId: 'dummyDestinationId', - dontBatch: false, - jobId: 1, - secret: {}, - sourceId: 'dummySourceId', - userId: 'dummyUserId', - workspaceId: 'dummyWorkspaceId', - }, + metadata: proxyMetdata, statusCode: 500, }, ], - statTags: { - destType: 'SALESFORCE', - destinationId: 'dummyDestinationId', - errorCategory: 'network', - errorType: 'retryable', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - workspaceId: 'dummyWorkspaceId', - }, + statTags: statTags.retryable, status: 500, }, }, @@ -358,29 +324,11 @@ export const testScenariosForV1API = [ response: [ { error: '{"error":"invalid_grant","error_description":"authentication failure"}', - metadata: { - attemptNum: 1, - destinationId: 'dummyDestinationId', - dontBatch: false, - jobId: 1, - secret: {}, - sourceId: 'dummySourceId', - userId: 'dummyUserId', - workspaceId: 'dummyWorkspaceId', - }, + metadata: proxyMetdata, statusCode: 400, }, ], - statTags: { - destType: 'SALESFORCE', - destinationId: 'dummyDestinationId', - errorCategory: 'network', - errorType: 'aborted', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - workspaceId: 'dummyWorkspaceId', - }, + statTags: statTags.aborted, status: 400, }, }, @@ -419,29 +367,11 @@ export const testScenariosForV1API = [ response: [ { error: '{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}', - metadata: { - attemptNum: 1, - destinationId: 'dummyDestinationId', - dontBatch: false, - jobId: 1, - secret: {}, - sourceId: 'dummySourceId', - userId: 'dummyUserId', - workspaceId: 'dummyWorkspaceId', - }, + metadata: proxyMetdata, statusCode: 500, }, ], - statTags: { - destType: 'SALESFORCE', - destinationId: 'dummyDestinationId', - errorCategory: 'network', - errorType: 'retryable', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - workspaceId: 'dummyWorkspaceId', - }, + statTags: statTags.retryable, status: 500, }, }, @@ -481,16 +411,7 @@ export const testScenariosForV1API = [ { error: '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', - metadata: { - attemptNum: 1, - destinationId: 'dummyDestinationId', - dontBatch: false, - jobId: 1, - secret: {}, - sourceId: 'dummySourceId', - userId: 'dummyUserId', - workspaceId: 'dummyWorkspaceId', - }, + metadata: proxyMetdata, statusCode: 200, }, ], @@ -500,221 +421,4 @@ export const testScenariosForV1API = [ }, }, }, - - // { - // id: 'salesforce_v1_scenario_4', - // name: 'salesforce', - // description: 'salesforce', - // successCriteria: '', - // scenario: 'Business', - // feature: 'dataDelivery', - // module: 'destination', - // version: 'v1', - // input: { - // request: { - // body: generateProxyV1Payload( - // { - // ...commonRequestParameters, - // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', - // }, - // reqMetadataArray, - // ), - // method: 'POST', - // }, - // }, - // output: { - // response: { - // status: 200, - // body: {}, - // }, - // }, - // }, - - // { - // id: 'salesforce_v1_scenario_4', - // name: 'salesforce', - // description: 'salesforce', - // successCriteria: '', - // scenario: 'Business', - // feature: 'dataDelivery', - // module: 'destination', - // version: 'v1', - // input: { - // request: { - // body: generateProxyV1Payload( - // { - // ...commonRequestParameters, - // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/4', - // }, - // reqMetadataArray, - // ), - // method: 'POST', - // }, - // }, - // output: { - // response: { - // status: 200, - // body: {}, - // }, - // }, - // }, - - // { - // id: 'salesforce_v1_scenario_3', - // name: 'salesforce', - // description: 'salesforce', - // successCriteria: '', - // scenario: 'Business', - // feature: 'dataDelivery', - // module: 'destination', - // version: 'v1', - // input: { - // request: { - // body: generateProxyV1Payload( - // { - // ...commonRequestParameters, - // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', - // }, - // reqMetadataArray, - // ), - // method: 'POST', - // }, - // }, - // output: { - // response: { - // status: 200, - // body: { - // output: { - // status: 500, - // message: - // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', - // response: [ - // { - // error: - // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', - // metadata: proxyMetdata, - // statusCode: 500, - // }, - // ], - // statTags: { - // destType: 'SALESFORCE', - // errorCategory: 'network', - // destinationId: 'dummyDestinationId', - // workspaceId: 'dummyWorkspaceId', - // errorType: 'retryable', - // feature: 'dataDelivery', - // implementation: 'native', - // module: 'destination', - // }, - // }, - // }, - // }, - // }, - // }, - - // { - // id: 'salesforce_v1_scenario_3', - // name: 'salesforce', - // description: 'salesforce', - // successCriteria: '', - // scenario: 'Business', - // feature: 'dataDelivery', - // module: 'destination', - // version: 'v1', - // input: { - // request: { - // body: generateProxyV1Payload( - // { - // ...commonRequestParameters, - // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', - // }, - // reqMetadataArray, - // ), - // method: 'POST', - // }, - // }, - // output: { - // response: { - // status: 200, - // body: { - // output: { - // status: 500, - // message: - // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', - // response: [ - // { - // error: - // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', - // metadata: proxyMetdata, - // statusCode: 500, - // }, - // ], - // statTags: { - // destType: 'SALESFORCE', - // errorCategory: 'network', - // destinationId: 'dummyDestinationId', - // workspaceId: 'dummyWorkspaceId', - // errorType: 'retryable', - // feature: 'dataDelivery', - // implementation: 'native', - // module: 'destination', - // }, - // }, - // }, - // }, - // }, - // }, - - // { - // id: 'salesforce_v1_scenario_3', - // name: 'salesforce', - // description: 'salesforce', - // successCriteria: '', - // scenario: 'Business', - // feature: 'dataDelivery', - // module: 'destination', - // version: 'v1', - // input: { - // request: { - // body: generateProxyV1Payload( - // { - // ...commonRequestParameters, - // endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/2', - // }, - // reqMetadataArray, - // ), - // method: 'POST', - // }, - // }, - // output: { - // response: { - // status: 200, - // body: { - // output: { - // status: 500, - // message: - // 'Salesforce Request Failed - due to "Session expired or invalid", (Retryable) during Salesforce Response Handling', - // response: [ - // { - // error: - // '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', - // metadata: proxyMetdata, - // statusCode: 500, - // }, - // ], - // statTags: { - // destType: 'SALESFORCE', - // errorCategory: 'network', - // destinationId: 'dummyDestinationId', - // workspaceId: 'dummyWorkspaceId', - // errorType: 'retryable', - // feature: 'dataDelivery', - // implementation: 'native', - // module: 'destination', - // }, - // }, - // }, - // }, - // }, - // }, ]; From a31bc12663d9b7aa41869d10e38d90bf0ba4ccd9 Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Sun, 11 Feb 2024 11:58:06 +0530 Subject: [PATCH 3/9] chore: add other scenario test, refactor --- .../salesforce/dataDelivery/business.ts | 117 +++--------------- .../salesforce/dataDelivery/data.ts | 3 +- .../salesforce/dataDelivery/other.ts | 47 +++++++ 3 files changed, 63 insertions(+), 104 deletions(-) diff --git a/test/integrations/destinations/salesforce/dataDelivery/business.ts b/test/integrations/destinations/salesforce/dataDelivery/business.ts index 2379807c13..5bc0b93229 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/business.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/business.ts @@ -51,7 +51,7 @@ const statTags = { }, }; -const proxyMetdata: ProxyMetdata = { +export const proxyMetdata: ProxyMetdata = { jobId: 1, attemptNum: 1, userId: 'dummyUserId', @@ -62,7 +62,7 @@ const proxyMetdata: ProxyMetdata = { dontBatch: false, }; -const reqMetadataArray = [proxyMetdata]; +export const reqMetadataArray = [proxyMetdata]; const commonRequestParameters = { headers: commonHeaders, @@ -71,7 +71,7 @@ const commonRequestParameters = { }; const externalIdSearchData = { Planning_Categories__c: 'pc', External_ID__c: 123 }; -const externalIDSearchedData = { +export const externalIDSearchedData = { headers: commonHeaders, JSON: externalIdSearchData, params, @@ -81,7 +81,7 @@ export const testScenariosForV1API = [ { id: 'salesforce_v1_scenario_1', name: 'salesforce', - description: 'Lead creation with existing unchanged leadId and unchanged data', + description: '[Proxy v1 API] :: Test for a valid request - Lead creation with existing unchanged leadId and unchanged data', successCriteria: 'Should return 200 with no error with destination response', scenario: 'Business', feature: 'dataDelivery', @@ -122,7 +122,7 @@ export const testScenariosForV1API = [ { id: 'salesforce_v1_scenario_2', name: 'salesforce', - description: 'salesforce', + description: '[Proxy v1 API] :: Test with invalid session id', successCriteria: 'Should return 5XX with error Session expired or invalid, INVALID_SESSION_ID', scenario: 'Business', feature: 'dataDelivery', @@ -166,8 +166,8 @@ export const testScenariosForV1API = [ { id: 'salesforce_v1_scenario_3', name: 'salesforce', - description: 'salesforce', - successCriteria: '', + description: '[Proxy v1 API] :: Test for Invalid Auth token passed in header', + successCriteria: 'Should return 401 INVALID_AUTH_HEADER', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -205,12 +205,11 @@ export const testScenariosForV1API = [ }, }, }, - { id: 'salesforce_v1_scenario_4', name: 'salesforce', - description: 'salesforce', - successCriteria: '', + description: '[Proxy v1 API] :: Test for rate limit exceeded scenario', + successCriteria: 'Should return 429 with error message "Request limit exceeded"', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -249,12 +248,11 @@ export const testScenariosForV1API = [ }, }, }, - { id: 'salesforce_v1_scenario_5', name: 'salesforce', - description: 'salesforce', - successCriteria: '', + description: '[Proxy v1 API] :: Test for server unavailable scenario', + successCriteria: 'Should return 500 with error message "Server Unavailable"', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -292,12 +290,11 @@ export const testScenariosForV1API = [ }, }, }, - { id: 'salesforce_v1_scenario_6', name: 'salesforce', - description: 'salesforce', - successCriteria: '', + description: '[Proxy v1 API] :: Test for invalid grant scenario due to authentication failure', + successCriteria: 'Should return 400 with error message "invalid_grant" due to "authentication failure"', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -334,91 +331,5 @@ export const testScenariosForV1API = [ }, }, }, - }, - - { - id: 'salesforce_v1_scenario_7', - name: 'salesforce', - description: 'salesforce', - successCriteria: '', - scenario: 'Business', - feature: 'dataDelivery', - module: 'destination', - version: 'v1', - input: { - request: { - body: generateProxyV1Payload( - { - ...commonRequestParameters, - endpoint: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/7', - }, - reqMetadataArray, - ), - method: 'POST', - }, - }, - output: { - response: { - status: 200, - body: { - output: { - message: - 'Salesforce Request Failed - due to "{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}", (Retryable) during Salesforce Response Handling', - response: [ - { - error: '{"message":"Server Unavailable","errorCode":"SERVER_UNAVAILABLE"}', - metadata: proxyMetdata, - statusCode: 500, - }, - ], - statTags: statTags.retryable, - status: 500, - }, - }, - }, - }, - }, - - { - id: 'salesforce_v1_scenario_8', - name: 'salesforce', - description: 'salesforce', - successCriteria: '', - scenario: 'Business', - feature: 'dataDelivery', - module: 'destination', - version: 'v1', - input: { - request: { - body: generateProxyV1Payload( - { - ...externalIDSearchedData, - endpoint: - 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', - }, - reqMetadataArray, - ), - method: 'POST', - }, - }, - output: { - response: { - status: 200, - body: { - output: { - message: 'Request for destination: salesforce Processed Successfully', - response: [ - { - error: - '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', - metadata: proxyMetdata, - statusCode: 200, - }, - ], - status: 200, - }, - }, - }, - }, - }, + } ]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/data.ts b/test/integrations/destinations/salesforce/dataDelivery/data.ts index 6aaa48b05f..d376289d97 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/data.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/data.ts @@ -1,6 +1,7 @@ import { AxiosError } from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { testScenariosForV1API } from './business'; +import { otherSalesforceScenariosV1 } from './other'; const legacyDataValue = { Email: 'danis.archurav@sbermarket.ru', @@ -742,4 +743,4 @@ const legacyTests = [ }, }, ]; -export const data = [...legacyTests, ...testScenariosForV1API]; +export const data = [...legacyTests, ...testScenariosForV1API, ...otherSalesforceScenariosV1]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/other.ts b/test/integrations/destinations/salesforce/dataDelivery/other.ts index e69de29bb2..b261fdc07f 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/other.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/other.ts @@ -0,0 +1,47 @@ +import { generateProxyV1Payload } from '../../../testUtils'; +import { externalIDSearchedData, reqMetadataArray, proxyMetdata } from './business'; + +export const otherSalesforceScenariosV1 = [ + { + id: 'salesforce_v1_scenario_7', + name: 'salesforce', + description: '[Proxy v1 API] :: Test for a valid request - External ID search', + successCriteria: 'Should return 200 with list of matching records with External ID', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...externalIDSearchedData, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: 'Request for destination: salesforce Processed Successfully', + response: [ + { + error: + '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', + metadata: proxyMetdata, + statusCode: 200, + }, + ], + status: 200, + }, + }, + }, + }, + }, +] \ No newline at end of file From d2c4f7c1633e01f7c26f6163c64012b15f4ef486 Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Tue, 13 Feb 2024 14:03:59 +0530 Subject: [PATCH 4/9] chore: address commentsx1 --- .../salesforce/dataDelivery/business.ts | 55 +++++++++++++++++-- .../salesforce/dataDelivery/data.ts | 3 +- .../salesforce/dataDelivery/other.ts | 47 ---------------- 3 files changed, 51 insertions(+), 54 deletions(-) delete mode 100644 test/integrations/destinations/salesforce/dataDelivery/other.ts diff --git a/test/integrations/destinations/salesforce/dataDelivery/business.ts b/test/integrations/destinations/salesforce/dataDelivery/business.ts index 5bc0b93229..4e98a3fc1a 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/business.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/business.ts @@ -1,4 +1,5 @@ import { ProxyMetdata } from '../../../../../src/types'; +import { ProxyV1TestData } from '../../../testTypes'; import { generateProxyV1Payload } from '../../../testUtils'; const commonHeaders = { @@ -77,11 +78,12 @@ export const externalIDSearchedData = { params, }; -export const testScenariosForV1API = [ +export const testScenariosForV1API: ProxyV1TestData[] = [ { id: 'salesforce_v1_scenario_1', name: 'salesforce', - description: '[Proxy v1 API] :: Test for a valid request - Lead creation with existing unchanged leadId and unchanged data', + description: + '[Proxy v1 API] :: Test for a valid request - Lead creation with existing unchanged leadId and unchanged data', successCriteria: 'Should return 200 with no error with destination response', scenario: 'Business', feature: 'dataDelivery', @@ -122,7 +124,7 @@ export const testScenariosForV1API = [ { id: 'salesforce_v1_scenario_2', name: 'salesforce', - description: '[Proxy v1 API] :: Test with invalid session id', + description: '[Proxy v1 API] :: Test with session expired scenario', successCriteria: 'Should return 5XX with error Session expired or invalid, INVALID_SESSION_ID', scenario: 'Business', feature: 'dataDelivery', @@ -294,7 +296,8 @@ export const testScenariosForV1API = [ id: 'salesforce_v1_scenario_6', name: 'salesforce', description: '[Proxy v1 API] :: Test for invalid grant scenario due to authentication failure', - successCriteria: 'Should return 400 with error message "invalid_grant" due to "authentication failure"', + successCriteria: + 'Should return 400 with error message "invalid_grant" due to "authentication failure"', scenario: 'Business', feature: 'dataDelivery', module: 'destination', @@ -331,5 +334,47 @@ export const testScenariosForV1API = [ }, }, }, - } + }, + { + id: 'salesforce_v1_scenario_7', + name: 'salesforce', + description: '[Proxy v1 API] :: Test for a valid request - External ID search', + successCriteria: 'Should return 200 with list of matching records with External ID', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...externalIDSearchedData, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: 'Request for destination: salesforce Processed Successfully', + response: [ + { + error: + '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', + metadata: proxyMetdata, + statusCode: 200, + }, + ], + status: 200, + }, + }, + }, + }, + }, ]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/data.ts b/test/integrations/destinations/salesforce/dataDelivery/data.ts index d376289d97..6aaa48b05f 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/data.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/data.ts @@ -1,7 +1,6 @@ import { AxiosError } from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { testScenariosForV1API } from './business'; -import { otherSalesforceScenariosV1 } from './other'; const legacyDataValue = { Email: 'danis.archurav@sbermarket.ru', @@ -743,4 +742,4 @@ const legacyTests = [ }, }, ]; -export const data = [...legacyTests, ...testScenariosForV1API, ...otherSalesforceScenariosV1]; +export const data = [...legacyTests, ...testScenariosForV1API]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/other.ts b/test/integrations/destinations/salesforce/dataDelivery/other.ts deleted file mode 100644 index b261fdc07f..0000000000 --- a/test/integrations/destinations/salesforce/dataDelivery/other.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { generateProxyV1Payload } from '../../../testUtils'; -import { externalIDSearchedData, reqMetadataArray, proxyMetdata } from './business'; - -export const otherSalesforceScenariosV1 = [ - { - id: 'salesforce_v1_scenario_7', - name: 'salesforce', - description: '[Proxy v1 API] :: Test for a valid request - External ID search', - successCriteria: 'Should return 200 with list of matching records with External ID', - scenario: 'Business', - feature: 'dataDelivery', - module: 'destination', - version: 'v1', - input: { - request: { - body: generateProxyV1Payload( - { - ...externalIDSearchedData, - endpoint: - 'https://rudderstack.my.salesforce.com/services/data/v50.0/parameterizedSearch/?q=123&sobject=object_name&in=External_ID__c&object_name.fields=id,External_ID__c', - }, - reqMetadataArray, - ), - method: 'POST', - }, - }, - output: { - response: { - status: 200, - body: { - output: { - message: 'Request for destination: salesforce Processed Successfully', - response: [ - { - error: - '{"searchRecords":[{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75100002w97gEAA"},"Id":"a0J75100002w97gEAA","External_ID__c":"external_id"},{"attributes":{"type":"object_name","url":"/services/data/v50.0/sobjects/object_name/a0J75200002w9ZsEAI"},"Id":"a0J75200002w9ZsEAI","External_ID__c":"external_id TEST"}]}', - metadata: proxyMetdata, - statusCode: 200, - }, - ], - status: 200, - }, - }, - }, - }, - }, -] \ No newline at end of file From a94c54d438e12fadf840f9c6ed5c5bb2d71e3905 Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:00:00 +0530 Subject: [PATCH 5/9] chore: move test to other --- .../salesforce/dataDelivery/data.ts | 3 +- .../salesforce/dataDelivery/other.ts | 123 ++++++++++++++++++ .../destinations/salesforce/network.ts | 23 +++- 3 files changed, 147 insertions(+), 2 deletions(-) create mode 100644 test/integrations/destinations/salesforce/dataDelivery/other.ts diff --git a/test/integrations/destinations/salesforce/dataDelivery/data.ts b/test/integrations/destinations/salesforce/dataDelivery/data.ts index 6aaa48b05f..d376289d97 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/data.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/data.ts @@ -1,6 +1,7 @@ import { AxiosError } from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { testScenariosForV1API } from './business'; +import { otherSalesforceScenariosV1 } from './other'; const legacyDataValue = { Email: 'danis.archurav@sbermarket.ru', @@ -742,4 +743,4 @@ const legacyTests = [ }, }, ]; -export const data = [...legacyTests, ...testScenariosForV1API]; +export const data = [...legacyTests, ...testScenariosForV1API, ...otherSalesforceScenariosV1]; diff --git a/test/integrations/destinations/salesforce/dataDelivery/other.ts b/test/integrations/destinations/salesforce/dataDelivery/other.ts new file mode 100644 index 0000000000..91761864ee --- /dev/null +++ b/test/integrations/destinations/salesforce/dataDelivery/other.ts @@ -0,0 +1,123 @@ +import { ProxyV1TestData } from '../../../testTypes'; +import { generateProxyV1Payload } from '../../../testUtils'; + +export const otherSalesforceScenariosV1: ProxyV1TestData[] = [ + { + id: 'salesforce_v1_other_scenario_1', + name: 'salesforce', + description: + '[Proxy v1 API] :: Scenario for testing Service Unavailable error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://sf_test_url/test_for_service_not_available', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: + '{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}', + statusCode: 500, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: false, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'SALESFORCE', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: + 'Salesforce Request Failed - due to "{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}", (Retryable) during Salesforce Response Handling', + status: 500, + }, + }, + }, + }, + }, + { + id: 'salesforce_v1_other_scenario_2', + name: 'salesforce', + description: '[Proxy v1 API] :: Scenario for testing Internal Server error from destination', + successCriteria: 'Should return 500 status code with error message', + scenario: 'Framework', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload({ + endpoint: 'https://random_test_url/test_for_internal_server_error', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + response: [ + { + error: '"Internal Server Error"', + statusCode: 500, + metadata: { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: false, + }, + }, + ], + statTags: { + errorCategory: 'network', + errorType: 'retryable', + destType: 'SALESFORCE', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + }, + message: + 'Salesforce Request Failed - due to ""Internal Server Error"", (Retryable) during Salesforce Response Handling', + status: 500, + }, + }, + }, + }, + }, +]; diff --git a/test/integrations/destinations/salesforce/network.ts b/test/integrations/destinations/salesforce/network.ts index fc341366aa..93013cd8db 100644 --- a/test/integrations/destinations/salesforce/network.ts +++ b/test/integrations/destinations/salesforce/network.ts @@ -12,7 +12,6 @@ const dataValue = { account_type__c: 'free_trial', }; - const tfProxyMocksData = [ { httpReq: { @@ -442,8 +441,30 @@ const businessMockData = [ }, ]; +const otherMocksData = [ + { + description: + 'Mock response from destination depicting a valid lead request, with no changed data', + httpReq: { + method: 'post', + url: 'https://sf_test_url/test_for_service_not_available', + }, + httpRes: { + data: { + error: { + message: 'Service Unavailable', + description: + 'The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later.', + }, + }, + status: 503, + }, + }, +]; + export const networkCallsData = [ ...tfProxyMocksData, ...transformationMocksData, ...businessMockData, + ...otherMocksData ]; From 8a3fbf4188d1c09d29eba7548b31b1c2b295dff1 Mon Sep 17 00:00:00 2001 From: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> Date: Sat, 2 Mar 2024 03:00:34 +0530 Subject: [PATCH 6/9] chore: address commentsx2 --- .../salesforce/dataDelivery/other.ts | 71 +++++++------------ 1 file changed, 27 insertions(+), 44 deletions(-) diff --git a/test/integrations/destinations/salesforce/dataDelivery/other.ts b/test/integrations/destinations/salesforce/dataDelivery/other.ts index 91761864ee..b3361caba7 100644 --- a/test/integrations/destinations/salesforce/dataDelivery/other.ts +++ b/test/integrations/destinations/salesforce/dataDelivery/other.ts @@ -1,6 +1,29 @@ import { ProxyV1TestData } from '../../../testTypes'; import { generateProxyV1Payload } from '../../../testUtils'; +const statTags = { + errorCategory: 'network', + errorType: 'retryable', + destType: 'SALESFORCE', + module: 'destination', + implementation: 'native', + feature: 'dataDelivery', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', +}; +const metadata = { + jobId: 1, + attemptNum: 1, + userId: 'default-userId', + destinationId: 'default-destinationId', + workspaceId: 'default-workspaceId', + sourceId: 'default-sourceId', + secret: { + accessToken: 'default-accessToken', + }, + dontBatch: false, +}; + export const otherSalesforceScenariosV1: ProxyV1TestData[] = [ { id: 'salesforce_v1_other_scenario_1', @@ -30,30 +53,10 @@ export const otherSalesforceScenariosV1: ProxyV1TestData[] = [ error: '{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}', statusCode: 500, - metadata: { - jobId: 1, - attemptNum: 1, - userId: 'default-userId', - destinationId: 'default-destinationId', - workspaceId: 'default-workspaceId', - sourceId: 'default-sourceId', - secret: { - accessToken: 'default-accessToken', - }, - dontBatch: false, - }, + metadata, }, ], - statTags: { - errorCategory: 'network', - errorType: 'retryable', - destType: 'SALESFORCE', - module: 'destination', - implementation: 'native', - feature: 'dataDelivery', - destinationId: 'default-destinationId', - workspaceId: 'default-workspaceId', - }, + statTags, message: 'Salesforce Request Failed - due to "{"error":{"message":"Service Unavailable","description":"The server is currently unable to handle the request due to temporary overloading or maintenance of the server. Please try again later."}}", (Retryable) during Salesforce Response Handling', status: 500, @@ -88,30 +91,10 @@ export const otherSalesforceScenariosV1: ProxyV1TestData[] = [ { error: '"Internal Server Error"', statusCode: 500, - metadata: { - jobId: 1, - attemptNum: 1, - userId: 'default-userId', - destinationId: 'default-destinationId', - workspaceId: 'default-workspaceId', - sourceId: 'default-sourceId', - secret: { - accessToken: 'default-accessToken', - }, - dontBatch: false, - }, + metadata, }, ], - statTags: { - errorCategory: 'network', - errorType: 'retryable', - destType: 'SALESFORCE', - module: 'destination', - implementation: 'native', - feature: 'dataDelivery', - destinationId: 'default-destinationId', - workspaceId: 'default-workspaceId', - }, + statTags, message: 'Salesforce Request Failed - due to ""Internal Server Error"", (Retryable) during Salesforce Response Handling', status: 500, From 3f47e6aaff7ec312586a858f16136e2d04482340 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Wed, 6 Mar 2024 18:34:30 +0530 Subject: [PATCH 7/9] chore: adding proxy test cases for salesforce oauth access token refresh --- .../salesforce_oauth/dataDelivery/data.ts | 3 + .../salesforce_oauth/dataDelivery/oauth.ts | 105 ++++++++++++++++++ .../destinations/salesforce_oauth/network.ts | 32 ++++++ 3 files changed, 140 insertions(+) create mode 100644 test/integrations/destinations/salesforce_oauth/dataDelivery/data.ts create mode 100644 test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts create mode 100644 test/integrations/destinations/salesforce_oauth/network.ts diff --git a/test/integrations/destinations/salesforce_oauth/dataDelivery/data.ts b/test/integrations/destinations/salesforce_oauth/dataDelivery/data.ts new file mode 100644 index 0000000000..bed8eec8db --- /dev/null +++ b/test/integrations/destinations/salesforce_oauth/dataDelivery/data.ts @@ -0,0 +1,3 @@ +import { testScenariosForV1API } from './oauth'; + +export const data = [...testScenariosForV1API]; diff --git a/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts new file mode 100644 index 0000000000..8a066bb2e4 --- /dev/null +++ b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts @@ -0,0 +1,105 @@ +import { ProxyMetdata } from '../../../../../src/types'; +import { ProxyV1TestData } from '../../../testTypes'; +import { generateProxyV1Payload } from '../../../testUtils'; + +const commonHeadersForWrongToken = { + Authorization: 'Bearer expiredAccessToken', + 'Content-Type': 'application/json', +}; +const params = { destination: 'salesforce_oauth' }; + +const users = [ + { + Email: 'danis.archurav@sbermarket.ru', + Company: 'itus.ru', + LastName: 'Danis', + FirstName: 'Archurav', + LeadSource: 'App Signup', + account_type__c: 'free_trial', + }, +]; + +const statTags = { + retryable: { + destType: 'SALESFORCE_OAUTH', + destinationId: 'dummyDestinationId', + errorCategory: 'network', + errorType: 'retryable', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'dummyWorkspaceId', + }, +}; + +const commonRequestParameters = { + headers: commonHeadersForWrongToken, + JSON: users[0], + params, +}; + +export const proxyMetdataWithSecret: ProxyMetdata = { + jobId: 1, + attemptNum: 1, + userId: 'dummyUserId', + sourceId: 'dummySourceId', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + secret: { + access_token: 'expiredAccessToken', + instanceUrl: 'https://rudderstack.my.salesforce_oauth.com', + }, + destInfo: { authKey: 'dummyDestinationId' }, + dontBatch: false, +}; + +export const reqMetadataArrayWithSecret = [proxyMetdataWithSecret]; + +export const testScenariosForV1API: ProxyV1TestData[] = [ + { + id: 'salesforce_v1_scenario_8', + name: 'salesforce_oauth', + description: '[Proxy v1 API] :: Test with expired access token scenario', + successCriteria: + 'Should return 5XX with error category REFRESH_TOKEN and Session expired or invalid, INVALID_SESSION_ID', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParameters, + endpoint: + 'https://rudderstack.my.salesforce_oauth.com/services/data/v50.0/sobjects/Lead/20', + }, + reqMetadataArrayWithSecret, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 500, + body: { + output: { + status: 500, + authErrorCategory: 'REFRESH_TOKEN', + message: + 'Salesforce Request Failed - due to "INVALID_SESSION_ID", (Retryable) during Salesforce Response Handling', + response: [ + { + error: + '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', + metadata: proxyMetdataWithSecret, + statusCode: 500, + }, + ], + statTags: statTags.retryable, + }, + }, + }, + }, + }, +]; diff --git a/test/integrations/destinations/salesforce_oauth/network.ts b/test/integrations/destinations/salesforce_oauth/network.ts new file mode 100644 index 0000000000..88b5936427 --- /dev/null +++ b/test/integrations/destinations/salesforce_oauth/network.ts @@ -0,0 +1,32 @@ +const headerWithWrongAccessToken = { + Authorization: 'Bearer expiredAccessToken', + 'Content-Type': 'application/json', +}; + +const dataValue = { + Email: 'danis.archurav@sbermarket.ru', + Company: 'itus.ru', + LastName: 'Danis', + FirstName: 'Archurav', + LeadSource: 'App Signup', + account_type__c: 'free_trial', +}; + +const businessMockData = [ + { + description: 'Mock response from destination depicting an expired access token', + httpReq: { + method: 'post', + url: 'https://rudderstack.my.salesforce_oauth.com/services/data/v50.0/sobjects/Lead/20', + headers: headerWithWrongAccessToken, + data: dataValue, + params: { destination: 'salesforce_oauth' }, + }, + httpRes: { + data: [{ message: 'Session expired or invalid', errorCode: 'INVALID_SESSION_ID' }], + status: 401, + }, + }, +]; + +export const networkCallsData = [...businessMockData]; From 90446d87389146a20698401d34be4028c2830b30 Mon Sep 17 00:00:00 2001 From: shrouti1507 <60211312+shrouti1507@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:31:49 +0530 Subject: [PATCH 8/9] code review suggestion Co-authored-by: Yashasvi Bajpai <33063622+yashasvibajpai@users.noreply.github.com> --- .../destinations/salesforce_oauth/dataDelivery/oauth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts index 8a066bb2e4..e03e671237 100644 --- a/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts +++ b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts @@ -57,7 +57,7 @@ export const reqMetadataArrayWithSecret = [proxyMetdataWithSecret]; export const testScenariosForV1API: ProxyV1TestData[] = [ { - id: 'salesforce_v1_scenario_8', + id: 'salesforce_v1_scenario_1', name: 'salesforce_oauth', description: '[Proxy v1 API] :: Test with expired access token scenario', successCriteria: From fb2bff14fca486dd57fd67f1b2236ab3a7576462 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Mon, 11 Mar 2024 16:35:20 +0530 Subject: [PATCH 9/9] fix: review comments address --- .../salesforce_oauth/dataDelivery/oauth.ts | 81 +++++++++++++++++-- .../destinations/salesforce_oauth/network.ts | 19 +++++ 2 files changed, 94 insertions(+), 6 deletions(-) diff --git a/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts index e03e671237..55eaa9cca1 100644 --- a/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts +++ b/test/integrations/destinations/salesforce_oauth/dataDelivery/oauth.ts @@ -6,6 +6,11 @@ const commonHeadersForWrongToken = { Authorization: 'Bearer expiredAccessToken', 'Content-Type': 'application/json', }; + +const commonHeadersForRightToken = { + Authorization: 'Bearer correctAccessToken', + 'Content-Type': 'application/json', +}; const params = { destination: 'salesforce_oauth' }; const users = [ @@ -32,13 +37,19 @@ const statTags = { }, }; -const commonRequestParameters = { +const commonRequestParametersWithWrongToken = { headers: commonHeadersForWrongToken, JSON: users[0], params, }; -export const proxyMetdataWithSecret: ProxyMetdata = { +const commonRequestParametersWithRightToken = { + headers: commonHeadersForRightToken, + JSON: users[0], + params, +}; + +export const proxyMetdataWithSecretWithWrongAccessToken: ProxyMetdata = { jobId: 1, attemptNum: 1, userId: 'dummyUserId', @@ -53,7 +64,23 @@ export const proxyMetdataWithSecret: ProxyMetdata = { dontBatch: false, }; -export const reqMetadataArrayWithSecret = [proxyMetdataWithSecret]; +export const proxyMetdataWithSecretWithRightAccessToken: ProxyMetdata = { + jobId: 1, + attemptNum: 1, + userId: 'dummyUserId', + sourceId: 'dummySourceId', + destinationId: 'dummyDestinationId', + workspaceId: 'dummyWorkspaceId', + secret: { + access_token: 'expiredRightToken', + instanceUrl: 'https://rudderstack.my.salesforce_oauth.com', + }, + destInfo: { authKey: 'dummyDestinationId' }, + dontBatch: false, +}; + +export const reqMetadataArrayWithWrongSecret = [proxyMetdataWithSecretWithWrongAccessToken]; +export const reqMetadataArray = [proxyMetdataWithSecretWithRightAccessToken]; export const testScenariosForV1API: ProxyV1TestData[] = [ { @@ -70,11 +97,11 @@ export const testScenariosForV1API: ProxyV1TestData[] = [ request: { body: generateProxyV1Payload( { - ...commonRequestParameters, + ...commonRequestParametersWithWrongToken, endpoint: 'https://rudderstack.my.salesforce_oauth.com/services/data/v50.0/sobjects/Lead/20', }, - reqMetadataArrayWithSecret, + reqMetadataArrayWithWrongSecret, ), method: 'POST', }, @@ -92,7 +119,7 @@ export const testScenariosForV1API: ProxyV1TestData[] = [ { error: '[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]', - metadata: proxyMetdataWithSecret, + metadata: proxyMetdataWithSecretWithWrongAccessToken, statusCode: 500, }, ], @@ -102,4 +129,46 @@ export const testScenariosForV1API: ProxyV1TestData[] = [ }, }, }, + { + id: 'salesforce_v1_scenario_2', + name: 'salesforce', + description: + '[Proxy v1 API] :: Test for a valid request - Lead creation with existing unchanged leadId and unchanged data', + successCriteria: 'Should return 200 with no error with destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...commonRequestParametersWithRightToken, + endpoint: + 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/existing_unchanged_leadId', + }, + reqMetadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + status: 200, + message: 'Request for destination: salesforce Processed Successfully', + response: [ + { + error: '{"statusText":"No Content"}', + metadata: proxyMetdataWithSecretWithRightAccessToken, + statusCode: 200, + }, + ], + }, + }, + }, + }, + }, ]; diff --git a/test/integrations/destinations/salesforce_oauth/network.ts b/test/integrations/destinations/salesforce_oauth/network.ts index 88b5936427..ae5f9d3fe4 100644 --- a/test/integrations/destinations/salesforce_oauth/network.ts +++ b/test/integrations/destinations/salesforce_oauth/network.ts @@ -3,6 +3,11 @@ const headerWithWrongAccessToken = { 'Content-Type': 'application/json', }; +const headerWithRightAccessToken = { + Authorization: 'Bearer correctAccessToken', + 'Content-Type': 'application/json', +}; + const dataValue = { Email: 'danis.archurav@sbermarket.ru', Company: 'itus.ru', @@ -27,6 +32,20 @@ const businessMockData = [ status: 401, }, }, + { + description: + 'Mock response from destination depicting a valid lead request, with no changed data', + httpReq: { + method: 'post', + url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/existing_unchanged_leadId', + data: dataValue, + headers: headerWithRightAccessToken, + }, + httpRes: { + data: { statusText: 'No Content' }, + status: 204, + }, + }, ]; export const networkCallsData = [...businessMockData];