Skip to content

Commit

Permalink
chore: adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Nov 5, 2024
1 parent d4aacf1 commit 21b65d0
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/v0/util/salesforce/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export const responseHandler = (destResponse: any, sourceMessage: string) => {
const { response, status } = destResponse;
const matchErrorCode = (errorCode) =>
response && Array.isArray(response) && response.some((resp) => resp?.errorCode === errorCode);
const matchErrorMessage = (messageCode) =>
response &&
Array.isArray(response) &&
response.some((resp) => resp?.message?.includes(messageCode));
switch (status) {
case 403:
if (matchErrorCode('REQUEST_LIMIT_EXCEEDED')) {
Expand All @@ -67,12 +71,12 @@ export const responseHandler = (destResponse: any, sourceMessage: string) => {

case 400:
if (
matchErrorCode('CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY') &&
(response?.message?.includes('UNABLE_TO_LOCK_ROW') ||
response?.message?.includes('Too many SOQL queries'))
(matchErrorCode('CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY') &&
matchErrorMessage('UNABLE_TO_LOCK_ROW')) ||
matchErrorMessage('Too many SOQL queries')
) {
throw new RetryableError(
`${DESTINATION} Request Failed - "${response.message}", (Retryable) ${sourceMessage}`,
`${DESTINATION} Request Failed - "${response[0].message}", (Retryable) ${sourceMessage}`,
500,
destResponse,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const proxyMetdata: ProxyMetdata = {

export const reqMetadataArray = [proxyMetdata];

const commonRequestParameters = {
export const commonRequestParameters = {
headers: commonHeaders,
JSON: users[0],
params,
Expand Down Expand Up @@ -377,4 +377,90 @@ export const testScenariosForV1API: ProxyV1TestData[] = [
},
},
},
{
id: 'salesforce_v1_scenario_8',
name: 'salesforce',
description: '[Proxy v1 API] :: Test for CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY scenario',
successCriteria: 'Should return 500 with error message "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"',
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/9',
},
reqMetadataArray,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message:
'Salesforce Request Failed - "UNABLE_TO_LOCK_ROW", (Retryable) during Salesforce Response Handling',
response: [
{
error:
'[{"message":"UNABLE_TO_LOCK_ROW","errorCode":"CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"}]',
metadata: proxyMetdata,
statusCode: 500,
},
],
statTags: statTags.retryable,
status: 500,
},
},
},
},
},
{
id: 'salesforce_v1_scenario_9',
name: 'salesforce',
description: '[Proxy v1 API] :: Test for CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY scenario',
successCriteria: 'Should return 500 with error message "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"',
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/10',
},
reqMetadataArray,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message:
'Salesforce Request Failed - "Too many SOQL queries", (Retryable) during Salesforce Response Handling',
response: [
{
error:
'[{"message":"Too many SOQL queries","errorCode":"CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"}]',
metadata: proxyMetdata,
statusCode: 500,
},
],
statTags: statTags.retryable,
status: 500,
},
},
},
},
},
];
36 changes: 36 additions & 0 deletions test/integrations/destinations/salesforce/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,42 @@ const tfProxyMocksData = [
status: 503,
},
},
{
httpReq: {
url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/9',
data: dataValue,
params: { destination: 'salesforce' },
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer token',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer token" is used as
authorization header
.
'User-Agent': 'RudderLabs',
},
method: 'POST',
},
httpRes: {
data: [{ message: 'UNABLE_TO_LOCK_ROW', errorCode: 'CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY' }],
status: 400,
},
},
{
httpReq: {
url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/10',
data: dataValue,
params: { destination: 'salesforce' },
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer token',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer token" is used as
authorization header
.
'User-Agent': 'RudderLabs',
},
method: 'POST',
},
httpRes: {
data: [
{ message: 'Too many SOQL queries', errorCode: 'CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY' },
],
status: 400,
},
},
{
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',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV1Payload } from '../../../testUtils';
import {
commonRequestParameters,
proxyMetdata,
reqMetadataArray,
} from '../../salesforce/dataDelivery/business';

const statTags = {
aborted: {
destType: 'SALESFORCE_OAUTH',
destinationId: 'dummyDestinationId',
errorCategory: 'network',
errorType: 'aborted',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'dummyWorkspaceId',
},
retryable: {
destType: 'SALESFORCE_OAUTH',
destinationId: 'dummyDestinationId',
errorCategory: 'network',
errorType: 'retryable',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'dummyWorkspaceId',
},
throttled: {
destType: 'SALESFORCE_OAUTH',
destinationId: 'dummyDestinationId',
errorCategory: 'network',
errorType: 'throttled',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'dummyWorkspaceId',
},
};

export const testScenarios: ProxyV1TestData[] = [
{
id: 'salesforce_v1_scenario_6',
name: 'salesforce_oauth',
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',
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: proxyMetdata,
statusCode: 400,
},
],
statTags: statTags.aborted,
status: 400,
},
},
},
},
},
];
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { testScenariosForV1API } from './oauth';
import { testScenarios } from './business';

export const data = [...testScenariosForV1API];
export const data = [...testScenariosForV1API, ...testScenarios];
18 changes: 18 additions & 0 deletions test/integrations/destinations/salesforce_oauth/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ const businessMockData = [
status: 204,
},
},

{
httpReq: {
url: 'https://rudderstack.my.salesforce.com/services/data/v50.0/sobjects/Lead/6',
data: dataValue,
params: { destination: 'salesforce_oauth' },
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer token',

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "Bearer token" is used as
authorization header
.
'User-Agent': 'RudderLabs',
},
method: 'POST',
},
httpRes: {
data: { error: 'invalid_grant', error_description: 'authentication failure' },
status: 400,
},
},
];

export const networkCallsData = [...businessMockData];

0 comments on commit 21b65d0

Please sign in to comment.