Skip to content

Commit

Permalink
fix: convert to string from null in hs (#3136)
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Feb 27, 2024
1 parent 4be2997 commit 75e9f46
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/v0/destinations/hs/util.js
Expand Up @@ -19,6 +19,7 @@ const {
getHashFromArray,
getDestinationExternalIDInfoForRetl,
getValueFromMessage,
isNull,
} = require('../../util');
const {
CONTACT_PROPERTY_MAP_ENDPOINT,
Expand Down Expand Up @@ -223,7 +224,9 @@ const getTransformedJSON = async (message, destination, propertyMap) => {
// lowercase and replace ' ' & '.' with '_'
const hsSupportedKey = formatKey(traitsKey);
if (!rawPayload[traitsKey] && propertyMap[hsSupportedKey]) {
let propValue = traits[traitsKey];
// HS accepts empty string to remove the property from contact
// https://community.hubspot.com/t5/APIs-Integrations/Clearing-values-of-custom-properties-in-Hubspot-contact-using/m-p/409156
let propValue = isNull(traits[traitsKey]) ? '' : traits[traitsKey];
if (propertyMap[hsSupportedKey] === 'date') {
propValue = getUTCMidnightTimeStampValue(propValue);
}
Expand Down
2 changes: 2 additions & 0 deletions src/v0/util/index.js
Expand Up @@ -52,6 +52,7 @@ const removeUndefinedAndNullAndEmptyValues = (obj) =>
lodash.pickBy(obj, isDefinedAndNotNullAndNotEmpty);
const isBlank = (value) => lodash.isEmpty(lodash.toString(value));
const flattenMap = (collection) => lodash.flatMap(collection, (x) => x);
const isNull = (x) => lodash.isNull(x);
// ========================================================================
// GENERIC UTLITY
// ========================================================================
Expand Down Expand Up @@ -2266,6 +2267,7 @@ module.exports = {
isDefinedAndNotNullAndNotEmpty,
isEmpty,
isNotEmpty,
isNull,
isEmptyObject,
isHttpStatusRetryable,
isHttpStatusSuccess,
Expand Down
104 changes: 104 additions & 0 deletions test/integrations/destinations/hs/processor/data.ts
@@ -1,3 +1,45 @@
import { Destination } from '../../../../../src/types';
import { generateMetadata, generateSimplifiedIdentifyPayload } from '../../../testUtils';

const commonOutputHeaders = {
'Content-Type': 'application/json',
Authorization: 'Bearer dummy-access-token',
};

const destination: Destination = {
Config: {
authorizationType: 'newPrivateAppApi',
accessToken: 'dummy-access-token',
hubID: 'dummy-hubId',
apiKey: 'dummy-apikey',
apiVersion: 'newApi',
lookupField: 'email',
hubspotEvents: [],
eventFilteringOption: 'disable',
blacklistedEvents: [
{
eventName: '',
},
],
whitelistedEvents: [
{
eventName: '',
},
],
},
Enabled: true,
ID: '123',
Name: 'hs',
DestinationDefinition: {
ID: '123',
Name: 'hs',
DisplayName: 'Hubspot',
Config: {},
},
WorkspaceID: '123',
Transformations: [],
};

export const data = [
{
name: 'hs',
Expand Down Expand Up @@ -5269,4 +5311,66 @@ export const data = [
},
},
},
{
name: 'hs',
description: 'Test coversion of null to string values',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: generateSimplifiedIdentifyPayload({
userId: '12345',
context: {
traits: {
email: 'noname@email.com',
firstname: null,
gender: '',
lookupField: 'email',
},
},
}),
metadata: generateMetadata(1),
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
userId: '',
method: 'POST',
endpoint: 'https://api.hubapi.com/crm/v3/objects/contacts',
files: {},
headers: commonOutputHeaders,
operation: 'createContacts',
params: {},
body: {
FORM: {},
JSON: {
properties: {
email: 'noname@email.com',
firstname: '',
gender: '',
},
},
JSON_ARRAY: {},
XML: {},
},
},
statusCode: 200,
metadata: generateMetadata(1),
},
],
},
},
},
];

0 comments on commit 75e9f46

Please sign in to comment.