Skip to content

Commit

Permalink
chore: update equality logic, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Sep 20, 2024
1 parent cf243a6 commit c345498
Show file tree
Hide file tree
Showing 3 changed files with 362 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/v0/destinations/salesforce/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,10 @@ async function getSaleforceIdForRecord(
);
}
const searchRecord = processedsfSearchResponse.response?.searchRecords?.find(
(rec) => typeof identifierValue !== 'undefined' && rec[identifierType] === identifierValue,
(rec) =>
typeof identifierValue !== 'undefined' &&
// eslint-disable-next-line eqeqeq
rec[identifierType] == identifierValue,
);

return searchRecord?.Id;
Expand Down
42 changes: 42 additions & 0 deletions test/integrations/destinations/salesforce/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,48 @@ const transformationMocksData = [
},
},
},
{
httpReq: {
url: 'https://ap15.salesforce.com/services/data/v50.0/parameterizedSearch/?q=72728&sobject=customobject2&in=CustomObject2__c&customobject2.fields=id,CustomObject2__c',
method: 'GET',
},
httpRes: {
status: 200,
data: {
searchRecords: [
{
attributes: {
type: 'CustomObject2__c',
url: '/services/data/v50.0/CustomObject2__c/id1101',
},
Id: 'id1101',
CustomObject2__c: 72728,
},
],
},
},
},
{
httpReq: {
url: 'https://ap15.salesforce.com/services/data/v50.0/parameterizedSearch/?q=72729&sobject=customobject2&in=CustomObject2__c&customobject2.fields=id,CustomObject2__c',
method: 'GET',
},
httpRes: {
status: 200,
data: {
searchRecords: [
{
attributes: {
type: 'CustomObject2__c',
url: '/services/data/v50.0/CustomObject2__c/id1102',
},
Id: 'id1102',
CustomObject2__c: '72729',
},
],
},
},
},
{
httpReq: {
url: 'https://ap15.salesforce.com/services/data/v50.0/parameterizedSearch/?q=ddv_ua%2B%7B%7B1234*245%7D%7D%40bugFix.com&sobject=Lead&Lead.fields=id,IsConverted,ConvertedContactId,IsDeleted',
Expand Down
316 changes: 316 additions & 0 deletions test/integrations/destinations/salesforce/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,4 +723,320 @@ export const data = [
},
},
},
{
name: 'salesforce_oauth',
description:
'Test 5: Sending custom object with external id of different type for Salesforce-Oauth (extId number, apiResponse string) ',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
message: {
anonymousId: '1e7673da-9473-49c6-97f7-da848ecafa76',
channel: 'web',
context: {
externalId: [
{
id: 72728,
type: 'SALESFORCE_OAUTH-CUSTOMOBJECT2',
identifierType: 'CustomObject2__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_oauth',
},
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/customobject2/id1101?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer dummy.access.token',
},
params: {},
body: {
JSON: {
CustomObject2__c: 72728,
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: [],
},
},
],
},
},
},
},
{
name: 'salesforce_oauth',
description:
'Test 6: Sending custom object with external id of different type for Salesforce-Oauth (extId string, apiResponse number) ',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
message: {
anonymousId: '1e7673da-9473-49c6-97f7-da848ecafa76',
channel: 'web',
context: {
externalId: [
{
id: '72729',
type: 'SALESFORCE_OAUTH-CUSTOMOBJECT2',
identifierType: 'CustomObject2__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_oauth',
},
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/customobject2/id1102?_HttpMethod=PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer dummy.access.token',
},
params: {},
body: {
JSON: {
CustomObject2__c: '72729',
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: [],
},
},
],
},
},
},
},
];

0 comments on commit c345498

Please sign in to comment.