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: convert to string from null in hs #3136

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/v0/destinations/hs/util.js
Original file line number Diff line number Diff line change
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
aashishmalik marked this conversation as resolved.
Show resolved Hide resolved
// 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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: [
{
aashishmalik marked this conversation as resolved.
Show resolved Hide resolved
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),
},
],
},
},
},
];