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

fix: use destination definition name in place of string for custom object #3737

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/v0/destinations/salesforce/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ async function getSalesforceIdFromPayload(
'Invalid externalId. id, type, identifierType must be provided',
);
}

const objectType = type.toLowerCase().replace('salesforce-', '');
const objectType = type
.toLowerCase()
.replace(`${destination.DestinationDefinition.Name.toLowerCase()}-`, '');
let salesforceId = id;

// Fetch the salesforce Id if the identifierType is not ID
Expand Down
18 changes: 14 additions & 4 deletions test/integrations/destinations/salesforce/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ const transformationMocksData = [
httpRes: {
status: 200,
data: {
access_token:
'00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
access_token: 'dummy.access.token',
instance_url: 'https://ap15.salesforce.com',
id: 'https://login.salesforce.com/id/00D2v000002lXbXEAU/0052v00000ga9WqAAI',
token_type: 'Bearer',
Expand All @@ -198,8 +197,7 @@ const transformationMocksData = [
httpRes: {
status: 200,
data: {
access_token:
'00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
access_token: 'dummy.access.token',
instance_url: 'https://ap15.salesforce.com',
id: 'https://login.salesforce.com/id/00D2v000002lXbXEAU/0052v00000ga9WqAAI',
token_type: 'Bearer',
Expand Down Expand Up @@ -245,6 +243,18 @@ const transformationMocksData = [
},
},
},
{
httpReq: {
url: 'https://ap15.salesforce.com/services/data/v50.0/parameterizedSearch/?q=72727&sobject=customobject&in=CustomObject__c&customobject.fields=id,CustomObject__c',
method: 'GET',
},
httpRes: {
status: 200,
data: {
searchRecords: [],
},
},
},
{
httpReq: {
url: 'https://ap15.salesforce.com/services/data/v50.0/parameterizedSearch/?q=peter.gibbons1%40initech.com&sobject=Lead&Lead.fields=id',
Expand Down
30 changes: 10 additions & 20 deletions test/integrations/destinations/salesforce/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -225,8 +224,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -354,8 +352,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -591,8 +588,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -721,8 +717,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -855,8 +850,7 @@
'https://ap15.salesforce.com/services/data/v50.0/sobjects/Contact/sf-contact-id?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -989,8 +983,7 @@
'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead/sf-contact-id?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
userId: '',
Expand Down Expand Up @@ -1117,8 +1110,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -1244,8 +1236,7 @@
'https://ap15.salesforce.com/services/data/v50.0/sobjects/custom_object__c/a005g0000383kmUAAQ?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -1360,8 +1351,7 @@
'https://ap15.salesforce.com/services/data/v50.0/sobjects/custom_object__c/a005g0000383kmUAAQ?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down
171 changes: 161 additions & 10 deletions test/integrations/destinations/salesforce/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -239,8 +238,7 @@
'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead/leadId?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -385,8 +383,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -456,8 +453,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -519,8 +515,7 @@
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/Lead',
headers: {
'Content-Type': 'application/json',
Authorization:
'Bearer 00D2v000002lXbX!ARcAQJBSGNA1Rq.MbUdtmlREscrN_nO3ckBz6kc4jRQGxqAzNkhT1XZIF0yPqyCQSnezWO3osMw1ewpjToO7q41E9.LvedWY',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
Expand Down Expand Up @@ -572,4 +567,160 @@
},
},
},
{
name: 'salesforce',
description: 'Test 4 : Sending custom object for Salesforce-Oauth ',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
message: {
anonymousId: '1e7673da-9473-49c6-97f7-da848ecafa76',
channel: 'web',
context: {
externalId: [
{
id: 72727,
type: 'SALESFORCE_OAUTH-CUSTOMOBJECT',
identifierType: 'CustomObject__c',
},
],
mappedToDestination: 'true',
app: {
build: '1.0.0',
name: 'RudderLabs JavaScript SDK',
namespace: 'com.rudderlabs.javascript',
version: '1.0.0',
},
ip: '0.0.0.0',
library: { name: 'RudderLabs JavaScript SDK', version: '1.0.0' },
locale: 'en-US',
os: { name: '', version: '' },
screen: { density: 2 },
traits: {
anonymousId: '1e7673da-9473-49c6-97f7-da848ecafa76',
company: 'Initech',
address: {
city: 'east greenwich',
country: 'USA',
state: 'California',
street: '19123 forest lane',
postalCode: '94115',
},
email: '[email protected]',
name: 'Peter Gibbons',
phone: '570-690-4150',
rating: 'Hot',
title: 'VP of Derp',
},
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
},
integrations: { All: true },
messageId: 'f19c35da-e9de-4c6e-b6e5-9e60cccc12c8',
originalTimestamp: '2020-01-27T12:20:55.301Z',
receivedAt: '2020-01-27T17:50:58.657+05:30',
request_ip: '14.98.244.60',
sentAt: '2020-01-27T12:20:56.849Z',
timestamp: '2020-01-27T17:50:57.109+05:30',
type: 'identify',
userId: '1e7673da-9473-49c6-97f7-da848ecafa76',
},
metadata: { jobId: 1, userId: 'u1' },
destination: {
Config: {
initialAccessToken: 'dummyInitialAccessToken',
password: 'dummyPassword1',
userName: '[email protected]',
},
DestinationDefinition: {
DisplayName: 'Salesforce-Oauth',
ID: '1T96GHZ0YZ1qQSLULHCoJkow9KC',
Name: 'SALESFORCE_OAUTH',
},
Enabled: true,
ID: '1WqFFH5esuVPnUgHkvEoYxDcX3y',
Name: 'tst',
Transformations: [],
},
},
],
destType: 'salesforce',
},
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batchedRequest: [
{
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://ap15.salesforce.com/services/data/v50.0/sobjects/customobject',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer dummy.access.token',
Dismissed Show dismissed Hide dismissed
},
params: {},
body: {
JSON: {
CustomObject__c: 72727,
address: {
postalCode: '94115',
city: 'east greenwich',
country: 'USA',
state: 'California',
street: '19123 forest lane',
},
anonymousId: '1e7673da-9473-49c6-97f7-da848ecafa76',
company: 'Initech',
email: '[email protected]',
name: 'Peter Gibbons',
phone: '570-690-4150',
rating: 'Hot',
title: 'VP of Derp',
},
XML: {},
JSON_ARRAY: {},
FORM: {},
},
files: {},
},
],
metadata: [
{ destInfo: { authKey: '1WqFFH5esuVPnUgHkvEoYxDcX3y' }, jobId: 1, userId: 'u1' },
],
batched: false,
statusCode: 200,
destination: {
Config: {
initialAccessToken: 'dummyInitialAccessToken',
password: 'dummyPassword1',
userName: '[email protected]',
},
DestinationDefinition: {
DisplayName: 'Salesforce-Oauth',
ID: '1T96GHZ0YZ1qQSLULHCoJkow9KC',
Name: 'SALESFORCE_OAUTH',
},
Enabled: true,
ID: '1WqFFH5esuVPnUgHkvEoYxDcX3y',
Name: 'tst',
Transformations: [],
},
},
],
},
},
},
},
];
Loading