Skip to content

Commit

Permalink
chore: should filter out falsey reserved attributes from Intercom des…
Browse files Browse the repository at this point in the history
…tination (#3767)

* Should filter out reserved attributes from Intercom destination even if they are falsey

* Fix presence check to allow null values

---------

Co-authored-by: Manish Kumar <[email protected]>
  • Loading branch information
2 people authored and Sai Sankeerth committed Nov 5, 2024
1 parent bad44cc commit 84224e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cdk/v2/destinations/intercom/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const filterCustomAttributes = (payload, type, destination, message) => {
let customAttributes = { ...get(payload, 'custom_attributes') };
if (customAttributes) {
ReservedAttributesList.forEach((trait) => {
if (customAttributes[trait]) delete customAttributes[trait];
if (trait in customAttributes) delete customAttributes[trait];
});
if (isDefinedAndNotNull(customAttributes) && Object.keys(customAttributes).length > 0) {
customAttributes =
Expand Down
12 changes: 12 additions & 0 deletions src/cdk/v2/destinations/intercom/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ describe('filterCustomAttributes utility test', () => {
expect(result).toBeUndefined();
});

it('Should filter out custom attributes that are reserved attributes and that are false', () => {
const payload = { custom_attributes: { unsubscribedFromEmails: false } };
const result = filterCustomAttributes(payload, 'user', { Config: { apiVersion: 'v2' } });
expect(result).toBeUndefined();
});

it('Should filter out custom attributes that are reserved attributes and that are null', () => {
const payload = { custom_attributes: { unsubscribedFromEmails: null } };
const result = filterCustomAttributes(payload, 'user', { Config: { apiVersion: 'v2' } });
expect(result).toBeUndefined();
});

it('Should return a flattened object when custom attributes are not null, not reserved attributes and nested', () => {
const payload = {
custom_attributes: { source: 'rudder-js-sdk', data: { nestedAttribute: 'nestedValue' } },
Expand Down

0 comments on commit 84224e1

Please sign in to comment.