From 84224e1d9628bfc48469540c1e96e54813852215 Mon Sep 17 00:00:00 2001 From: Will Date: Thu, 17 Oct 2024 04:59:12 +0100 Subject: [PATCH] chore: should filter out falsey reserved attributes from Intercom destination (#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 <144022547+manish339k@users.noreply.github.com> --- src/cdk/v2/destinations/intercom/utils.js | 2 +- src/cdk/v2/destinations/intercom/utils.test.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cdk/v2/destinations/intercom/utils.js b/src/cdk/v2/destinations/intercom/utils.js index 22af726e84..a75f8155af 100644 --- a/src/cdk/v2/destinations/intercom/utils.js +++ b/src/cdk/v2/destinations/intercom/utils.js @@ -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 = diff --git a/src/cdk/v2/destinations/intercom/utils.test.js b/src/cdk/v2/destinations/intercom/utils.test.js index c2bf3f8e89..e2c1fb9a07 100644 --- a/src/cdk/v2/destinations/intercom/utils.test.js +++ b/src/cdk/v2/destinations/intercom/utils.test.js @@ -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' } },