Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adding salesforce oauth sandbox support for closed testing #3778

Merged
merged 9 commits into from
Oct 8, 2024
1 change: 1 addition & 0 deletions src/constants/destinationCanonicalNames.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const DestHandlerMap = {
ga360: 'ga',
salesforce_oauth: 'salesforce',
salesforce_oauth_sandbox: 'salesforce',
};

const DestCanonicalNames = {
Expand Down
1 change: 1 addition & 0 deletions src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"PROFITWELL": true,
"SALESFORCE": true,
"SALESFORCE_OAUTH": true,
"SALESFORCE_OAUTH_SANDBOX": true,
"SFMC": true,
"SNAPCHAT_CONVERSION": true,
"TIKTOK_ADS": true,
Expand Down
34 changes: 34 additions & 0 deletions src/v0/destinations/salesforce_oauth_sandbox/networkHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network');
const { processAxiosResponse } = require('../../../adapters/utils/networkUtils');
const { OAUTH } = require('../salesforce/config');
const { salesforceResponseHandler } = require('../salesforce/utils');

const responseHandler = (responseParams) => {
const { destinationResponse, destType, rudderJobMetadata } = responseParams;
const message = `Request for destination: ${destType} Processed Successfully`;

salesforceResponseHandler(
destinationResponse,
'during Salesforce Response Handling',
rudderJobMetadata?.destInfo?.authKey,
OAUTH,
);

// else successfully return status as 200, message and original destination response
return {

Check warning on line 18 in src/v0/destinations/salesforce_oauth_sandbox/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/salesforce_oauth_sandbox/networkHandler.js#L18

Added line #L18 was not covered by tests
status: 200,
message,
destinationResponse,
};
};

function networkHandler() {
this.responseHandler = responseHandler;
this.proxy = proxyRequest;
this.prepareProxy = prepareProxyRequest;
this.processAxiosResponse = processAxiosResponse;
}

module.exports = {
networkHandler,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { testScenariosForV1API } from './oauth';

export const data = [...testScenariosForV1API];
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import { ProxyMetdata } from '../../../../../src/types';
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV1Payload } from '../../../testUtils';

const commonHeadersForWrongToken = {
Authorization: 'Bearer expiredAccessToken',
Dismissed Show dismissed Hide dismissed
'Content-Type': 'application/json',
};

const commonHeadersForRightToken = {
Authorization: 'Bearer correctAccessToken',
Dismissed Show dismissed Hide dismissed
'Content-Type': 'application/json',
};
const params = { destination: 'salesforce_oauth_sandbox' };

const users = [
{
Email: '[email protected]',
Company: 'itus.ru',
LastName: 'Danis',
FirstName: 'Archurav',
LeadSource: 'App Signup',
account_type__c: 'free_trial',
},
];

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

const commonRequestParametersWithWrongToken = {
headers: commonHeadersForWrongToken,
JSON: users[0],
params,
};

const commonRequestParametersWithRightToken = {
headers: commonHeadersForRightToken,
JSON: users[0],
params,
};

export const proxyMetdataWithSecretWithWrongAccessToken: ProxyMetdata = {
jobId: 1,
attemptNum: 1,
userId: 'dummyUserId',
sourceId: 'dummySourceId',
destinationId: 'dummyDestinationId',
workspaceId: 'dummyWorkspaceId',
secret: {
access_token: 'expiredAccessToken',
instanceUrl: 'https://rudderstack.my.salesforce_oauth_sandbox.com',
},
destInfo: { authKey: 'dummyDestinationId' },
dontBatch: false,
};

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_sandbox.com',
},
destInfo: { authKey: 'dummyDestinationId' },
dontBatch: false,
};

export const reqMetadataArrayWithWrongSecret = [proxyMetdataWithSecretWithWrongAccessToken];
export const reqMetadataArray = [proxyMetdataWithSecretWithRightAccessToken];

export const testScenariosForV1API: ProxyV1TestData[] = [
{
id: 'salesforce_v1_scenario_1',
name: 'salesforce_oauth_sandbox',
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(
{
...commonRequestParametersWithWrongToken,
endpoint:
'https://rudderstack.my.salesforce_oauth_sandbox.com/services/data/v50.0/sobjects/Lead/20',
},
reqMetadataArrayWithWrongSecret,
),
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: proxyMetdataWithSecretWithWrongAccessToken,
statusCode: 500,
},
],
statTags: statTags.retryable,
},
},
},
},
},
{
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,
},
],
},
},
},
},
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const headerWithWrongAccessToken = {
Authorization: 'Bearer expiredAccessToken',
Dismissed Show dismissed Hide dismissed
'Content-Type': 'application/json',
};

const headerWithRightAccessToken = {
Authorization: 'Bearer correctAccessToken',
Dismissed Show dismissed Hide dismissed
'Content-Type': 'application/json',
};

const dataValue = {
Email: '[email protected]',
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_sandbox.com/services/data/v50.0/sobjects/Lead/20',
headers: headerWithWrongAccessToken,
data: dataValue,
params: { destination: 'salesforce_oauth_sandbox' },
},
httpRes: {
data: [{ message: 'Session expired or invalid', errorCode: 'INVALID_SESSION_ID' }],
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];
Loading